I am using jquery data table plugin to populate data in web table using ajax.But i want to populate data by calling a method which is present in js file without making ajax call.Is there any way?
Sharing my code.
ajax : $.fn.dataTable.pipelineAdv({
url : oMapUrls.loadDefaultMap,
pages : !bLivePaginate ? -1 : Global.pageSize,
method : "POST",
contentType : "application/json",
data : function() {
var requestData = {
serverSide : false
};
if (bTimeFiltered) {
requestData.withInTime = iFilterByTime;
}
if (sFilteredVehicleIds) {
requestData.vehicleIds = sFilteredVehicleIds;
}
return requestData;
},
redraw : function() {
return (getPageName() === "map");
},
callback : function(oJSON, request) {
aLiveFleetData = oJSON.serverResponse.result;
if (mapRefreshTimer) {
window.clearTimeout(mapRefreshTimer);
}
setMapRefreshTimer();
}
}),
oCustomization : {
sExportFunctionCall : oMapUrls.exportLiveFleetReport,
bAdvanceExport : true,
bShowDefaultAll : !bLivePaginate
},
pageLength : !bLivePaginate ? -1 : Global.rowLength,
scrollCollapse : false,
scrollY : iDataTableHeight,
serverSide : bLivePaginate,
order : [ [ 3, "desc" ] ],
columns : [
{
"data" : "trackeeName",
"width" : aColumnWidths[0],
"class" : "no-word-break",
"settings" : {
source : function(request, oCallback) {
oCallback($.ui.autoplete.filter(Global.aJSTreeVehicleItems || [], request.term));
}
},
"title" : jQuery.i18n.prop("report.columnTitle.vehicle"),
"render" : function(value, type, rowData) {
if (type == "display") {
rowData.formattedDate = Global.getTimeStampToDate(rowData.dateAndTime, rowData.offset,
rowData.timeZone);
}
return rowData.trackeeName;
}
},
{
"data" : "firstName",
"width" : aColumnWidths[1],
"class" : "no-word-break",
settings : {
source : Global.getDriverSuggestion
},
"title" : jQuery.i18n.prop("driver.title.txtInfo"),
"visible" : Global['show.driver.in.reports'] == 1,
"render" : function(value, type, rowData) {
return getUserName(rowData.firstName, rowData.lastName);
}
},
{
"data" : "groupName",
"width" : aColumnWidths[2],
"class" : "no-word-break",
"settings" : {
source : function(request, oCallback) {
oCallback($.ui.autoplete.filter(Global.aJSTreeGroupItems || [], request.term));
}
},
I make an Ajax call by passing url and get the data in json format, but i want to call a method which has data and pass it to to data table, without making ajax call.
I am using jquery data table plugin to populate data in web table using ajax.But i want to populate data by calling a method which is present in js file without making ajax call.Is there any way?
Sharing my code.
ajax : $.fn.dataTable.pipelineAdv({
url : oMapUrls.loadDefaultMap,
pages : !bLivePaginate ? -1 : Global.pageSize,
method : "POST",
contentType : "application/json",
data : function() {
var requestData = {
serverSide : false
};
if (bTimeFiltered) {
requestData.withInTime = iFilterByTime;
}
if (sFilteredVehicleIds) {
requestData.vehicleIds = sFilteredVehicleIds;
}
return requestData;
},
redraw : function() {
return (getPageName() === "map");
},
callback : function(oJSON, request) {
aLiveFleetData = oJSON.serverResponse.result;
if (mapRefreshTimer) {
window.clearTimeout(mapRefreshTimer);
}
setMapRefreshTimer();
}
}),
oCustomization : {
sExportFunctionCall : oMapUrls.exportLiveFleetReport,
bAdvanceExport : true,
bShowDefaultAll : !bLivePaginate
},
pageLength : !bLivePaginate ? -1 : Global.rowLength,
scrollCollapse : false,
scrollY : iDataTableHeight,
serverSide : bLivePaginate,
order : [ [ 3, "desc" ] ],
columns : [
{
"data" : "trackeeName",
"width" : aColumnWidths[0],
"class" : "no-word-break",
"settings" : {
source : function(request, oCallback) {
oCallback($.ui.autoplete.filter(Global.aJSTreeVehicleItems || [], request.term));
}
},
"title" : jQuery.i18n.prop("report.columnTitle.vehicle"),
"render" : function(value, type, rowData) {
if (type == "display") {
rowData.formattedDate = Global.getTimeStampToDate(rowData.dateAndTime, rowData.offset,
rowData.timeZone);
}
return rowData.trackeeName;
}
},
{
"data" : "firstName",
"width" : aColumnWidths[1],
"class" : "no-word-break",
settings : {
source : Global.getDriverSuggestion
},
"title" : jQuery.i18n.prop("driver.title.txtInfo"),
"visible" : Global['show.driver.in.reports'] == 1,
"render" : function(value, type, rowData) {
return getUserName(rowData.firstName, rowData.lastName);
}
},
{
"data" : "groupName",
"width" : aColumnWidths[2],
"class" : "no-word-break",
"settings" : {
source : function(request, oCallback) {
oCallback($.ui.autoplete.filter(Global.aJSTreeGroupItems || [], request.term));
}
},
I make an Ajax call by passing url and get the data in json format, but i want to call a method which has data and pass it to to data table, without making ajax call.
Share Improve this question edited Feb 12, 2016 at 5:50 Insane Skull 9,3789 gold badges47 silver badges65 bronze badges asked Feb 10, 2016 at 5:11 user3660375user3660375 931 gold badge2 silver badges11 bronze badges 4- could you share your code ? – Niklesh Raut Commented Feb 10, 2016 at 5:15
- have you read the documentation for this jquery data table plugin – Jaromanda X Commented Feb 10, 2016 at 5:16
- I have shared the code @LearningMode. – user3660375 Commented Feb 10, 2016 at 5:38
- Thanks for sharing the document @JaromandaX – user3660375 Commented Feb 10, 2016 at 5:38
1 Answer
Reset to default 7You can set custom data by setting data
option. Examples and usage details are here http://datatables/reference/option/data. Set data option as a function which returns preferred array of data.