Site icon Hip-Hop Website Design and Development

javascript datatables in a plugin

i’ve a plugin that i’ve began growing, and that i wish to attempt to use datatables.internet to show desk knowledge. i wasn’t positive learn how to obtain this, and after looking out and making an attempt completely different stuff i am misplaced. this is what i’ve in my plugin. at present, when i load the web page it shows the desk, and that i can see within the web page supply that the dataTables-js, dataTables-css, and customScriptDatatables are loaded.

add_action('create_datatable', 'show_datatable');
perform show_datatable (){

perform add_datatables_javaScript (){
        wp_register_script( 'dataTables-js', 'https://cdn.datatables.internet/1.10.16/js/jquery.dataTables.min.js' , '', '', true );
        wp_register_script( 'customScriptDatatables', plugins_url( 'contains/js/customScriptDatatables.js', __FILE__, '', true ) );
        wp_register_style( 'dataTables-css', 'https://cdn.datatables.internet/1.10.16/css/jquery.dataTables.min.css', '', '', true );

        wp_enqueue_script( 'dataTables-js' );
        wp_enqueue_script( 'customScriptDatatables' );
        wp_enqueue_style( 'dataTables-css' );
}
add_action( 'load_datatables_javascript', 'add_datatables_javaScript' );

world $wpdb;
$getTheRows = $wpdb->get_results(
        $wpdb->put together( "SELECT date,id_result FROM tableName the place user_id=2" )
); # $getTheRows =...

echo '<desk id="dataTable"';
echo "<tr><th>Date</th><th>ID</th></tr>";
foreach($getTheRows as $gotRow){
        $date = $gotRow->date;
        $id = $gotRow->id_result;
echo "<tr><td>" . $date . "</td><td>" . $id . "</td></tr>";
}

echo "</desk>";
} # perform show_datatable

inside my plugin listing is an contains listing and inside that may be a js listing. i put customScriptDatatables.js in there, and put the default datatables.internet instance in that with a reference to id dataTable. customScriptDatatables.js is beneath:

$(doc).prepared( perform () {
$('#dataTable').DataTable();
} );

i am new to wordpress and javascript so forgive any unknown ignorance and dangerous practice- however please be at liberty to appropriate me. the plan was to place completely different features for various tables within the customScriptDatatables.js file and cargo it in pages the place i wished to make use of datatables, however i am not getting a datatables trying desk. can somebody inform me the place i went unsuitable? or perhaps counsel a greater approach? i am not solely positive the place to write down the javascript code, and that is why i put it in a .js file and tried to make use of wp_enqueue_script.
thanks!