Change datasource on click
Change datasource on click
DespyNL
Posts: 4Questions: 3Answers: 0
Hi,
On page load I display the JSON output of employee.php in a datatable. By clicking on the student button I want to change the datasource to students.php.
To this point this works, but I am stuck with the aoColumns. How can I customize the column by clicking on the student button? The student JSON output has different column names. I also would like to associate the rowId to another field.
$(document).ready(function () {
dt = $('#peopleTable').DataTable({
ajax: {
"url": '/employee.php',
"dataSrc" : ""
},
sDom: '<"toolbar">Bfrtp',
aoColumns: [
{ data: "id", visible: false },
{ sTitle: "Lastname", data: "lastname", sWidth: "200px" },
{ sTitle: "Initials", data: "initials", sWidth: "75px" },
{ sTitle: "Company", data: "company", sWidth: "200px" },
{ sTitle: "Employee", data: "employee", sWidth: "200px" },
{ sTitle: "Modified", data: "modified", sWidth: "150px" }
],
select: true,
rowId: 'id',
deferRender: true
});
setInterval(function() {
dt.ajax.reload(null, false);
}, 5000);
$('.studentbutton').on('click', function() {
dt.ajax.url('students.php').load();
});
});
Help is appreciated.
Thanks,
Dennis
This discussion has been closed.
Answers
Okay, it took a while before I realized what needs to be done to achieve this. The best solution I can think of now is to re-initialize the table.
For now this seems to work.