How to incorporate Datatable in JQuery Onclick Function
How to incorporate Datatable in JQuery Onclick Function
I have an li
<li id="clientshowall"><a href="#"><span>Show All Clients</span>
// This Function retrieves all the Clients from my mysql database.
$(function(){
$("#clientshowall").on('click', function(){
$.ajax({
method: "GET",
url: "client_tables.php",
}).done(function( data ) {
var result= $.parseJSON(data);
var string='
customer Number | First Name | Last Name | Email Address | Cell Phone | '; /* from result create a string of data and append to the div */ $.each( result, function( key, value ) { string += "
---|---|---|---|---|
"+value['customer_number']+ " | " +value['first_name']+ " | " +value['last_name']+ " | " +value['email']+ " | " +value['primary_phone']+ " |
';
$("#payments").html(string);
});
});
});
See Attached of the table.
I would like to use datatables in the above function, but I do not know how to incorporate into this function. If some one caould give me a pointer I would be most appreciative.
thanks
Answers
Kevin's example from this thread should get you going,
Colin
solved. thanks
///jquery code
$(function(){
$("#clientshowall").on('click', function(){
$.ajax({
method: "GET",
url: "client_tables.php",
success: function (data) {
data = JSON.parse(data);
$("#clienttable").show();
$('#clienttable').DataTable
({
"dom": '<"top"Biflp><"clear">' ,
data: data
});
}
});
});
});
/// client_table.php
<?php
session_start();
include 'email_db_include.php';
doDB(); // Connect to server and select databse.
<?php > ?>$get_sql="select customer_number, first_name, last_name, email, primary_phone from client_table order by last_name";
$check_res = mysqli_query($conn, $get_sql);
$json=array();
while($newArray = mysqli_fetch_array($check_res))
{
$json[]=$newArray;
}
echo json_encode($json);
mysqli_close($conn);