Display records from database on page load using ajax and datatables 1.9.
Display records from database on page load using ajax and datatables 1.9.
drchanix
Posts: 20Questions: 0Answers: 0
Hi. I am new to DataTables. I need some help.
On page load, I call ajax to pull records from the database. --> Working fine.
How can I achieve displaying the records using the datatables?
Here are my references:
Here is my html:
First Name
Last Name
Email
Here is my ajax:
$(document).ready(function () {
$.getJSON("GetMethod", "", function (data) {
$.each(data, function (value) {
$(""
+ value["FirstName"]
+ ""
+ value["LastName"]
+ ""
+ value["Email"]
+ "")
.appendTo("#tbodyTest");
});
});
$('#tableList').dataTable({
"sPaginationType": "full_numbers",
"bDestroy": true
});
});
The result:
Show 10 entries (showing) Search box (showing)
First Name Last Name Email (table headers)
No data available in table
FName1 LName1 Email1@test.com
FName2 LName2 Email2@test.com
FName3 LName3 Email3@test.com
Showing 0 to 0 of 0 entries (navigation buttons)
Any help will do.
Thanks.
On page load, I call ajax to pull records from the database. --> Working fine.
How can I achieve displaying the records using the datatables?
Here are my references:
Here is my html:
First Name
Last Name
Here is my ajax:
$(document).ready(function () {
$.getJSON("GetMethod", "", function (data) {
$.each(data, function (value) {
$(""
+ value["FirstName"]
+ ""
+ value["LastName"]
+ ""
+ value["Email"]
+ "")
.appendTo("#tbodyTest");
});
});
$('#tableList').dataTable({
"sPaginationType": "full_numbers",
"bDestroy": true
});
});
The result:
Show 10 entries (showing) Search box (showing)
First Name Last Name Email (table headers)
No data available in table
FName1 LName1 Email1@test.com
FName2 LName2 Email2@test.com
FName3 LName3 Email3@test.com
Showing 0 to 0 of 0 entries (navigation buttons)
Any help will do.
Thanks.
This discussion has been closed.
Replies
Updated code:
$.getJSON("GetMethod", "", function (data) {
$.each(data, function (value) {
$(""
+ value["FirstName"]
+ ""
+ value["LastName"]
+ ""
+ value["Email"]
+ "")
.appendTo("#tbodyTest");
});
});
$(document).ready(function () {
$('#tableList').dataTable({
"sPaginationType": "full_numbers",
"bDestroy": true
});
});
Kindly help me.
Thanks.
And thanks to Allan for the great help.