I am using this dataTable code to load a table data.
var table = $('#fileInfoTable').DataTable({
"sAjaxSource": "api/file/loadAll",
"sAjaxDataProp": "",
"order": [
[0, "asc"]
],
"aoColumns": [{
"mData": "fileId"
}, {
"mData": "fileName"
}, {
"mData": "sentDate"
}, {
"mData": "direction"
}, {
"mData": "interfaceType"
}, {
"mData": "buisnessLine"
}, {
"mData": "vaultName"
}, {
"mData": "manageCompony"
}, {
"mData": "lastActivity"
}, {
"mData": "lastActivityStatus"
}, {
"mData": "feedbackName"
}, {
"mData": "feedbackDate"
}, {
"mData": "processDate"
}, {
"mData": "eventsAmount"
}, {
"mData": "goodEventsAmount"
}, {
"mData": "sourceId"
}]
});
It works fine if I load it on page load but I need to be able to load the data by clicking a button and not on page load. How can I do it?
Edit: now I am using this code below and I can see the alert but the table is undefined
$(document).ready(function () {
var table = $('#fileInfoTable').DataTable({
data: [],
"order": [
[0, "asc"]
],
"aoColumns": [{
"mData": "fileId"
}, {
"mData": "fileName"
}, {
"mData": "sentDate"
}, {
"mData": "direction"
}, {
"mData": "interfaceType"
}, {
"mData": "buisnessLine"
}, {
"mData": "vaultName"
}, {
"mData": "manageCompony"
}, {
"mData": "lastActivity"
}, {
"mData": "lastActivityStatus"
}, {
"mData": "feedbackName"
}, {
"mData": "feedbackDate"
}, {
"mData": "processDate"
}, {
"mData": "eventsAmount"
}, {
"mData": "goodEventsAmount"
}, {
"mData": "sourceId"
}]
})
$("#loadData").on('click', function () {
alert("ppp:" + table.name);
table.ajax.url("api/file/loadAll").load();
})
});
$(document).ready(function() {s*** :) I cannot know for sure, but I have the feeling you are making it all too complicated and by that messes up the scope for your variables.#loadDataelement located..? If it is inside the table, attach the event handler in ainitCompleteordrawCallbackcallback. Again, really hard just to guess without more info.