FixedColumns - oDT is undefined unless processed on server
FixedColumns - oDT is undefined unless processed on server
parliament718
Posts: 2Questions: 0Answers: 0
I'm experience a strange bug where I'm unable to call fnCallback successfully unless I call it inside an ajax success callback. However, sometimes the table already has the data it needs in the cache (from a previous request) and I want to avoid an unneccesary request (thus the "preventDataRequest" flag). However, if I take the control flow, I get "oDT is undefined" from FixedColumns down the line. The models passed into each fnCallback are identical so why is this happening?
[code] self.dataTable = $(self.tableSelector).dataTable({
bServerSide: true,
fnServerData: function (sSource, aoData, fnCallback) {
//Convert [{ "name" : "sEcho", "value" : 1},{ "name" : "iColumns", "value" : 12}, ... ]
//Into { sEcho: 1, iColumns: 12, ... }
var dataTableQuery = _.object(_.map(aoData, function (x) { return [x.name, x.value]; }));
if (self.preventDataRequests) {
self.resultSetModel.DataTableModel.sEcho = dataTableQuery.sEcho;
fnCallback(self.resultSetModel.DataTableModel); //This causes the error
} else {
var resultSetQuery= {
DataTableQuery: dataTableQuery
};
$.ajax({
contentType: 'application/json',
dataType: 'json',
type: 'POST',
url: "/Controller/Action",
data: JSON.stringify(resultSetQuery),
success: function(resultSetModel) {
fnCallback(resultSetModel.DataTableModel); //This works fine
}
});
}
},
fnInitComplete: function(settings, json) {
//If ajax request was not made (when self.preventDataRequest == true), then self.dataTable equalls undefined here and results in "oDT is undefined error"
self.dataTableFixedColumns = new FixedColumns(self.dataTable, {
...
});
},
}) [/code]
[code] self.dataTable = $(self.tableSelector).dataTable({
bServerSide: true,
fnServerData: function (sSource, aoData, fnCallback) {
//Convert [{ "name" : "sEcho", "value" : 1},{ "name" : "iColumns", "value" : 12}, ... ]
//Into { sEcho: 1, iColumns: 12, ... }
var dataTableQuery = _.object(_.map(aoData, function (x) { return [x.name, x.value]; }));
if (self.preventDataRequests) {
self.resultSetModel.DataTableModel.sEcho = dataTableQuery.sEcho;
fnCallback(self.resultSetModel.DataTableModel); //This causes the error
} else {
var resultSetQuery= {
DataTableQuery: dataTableQuery
};
$.ajax({
contentType: 'application/json',
dataType: 'json',
type: 'POST',
url: "/Controller/Action",
data: JSON.stringify(resultSetQuery),
success: function(resultSetModel) {
fnCallback(resultSetModel.DataTableModel); //This works fine
}
});
}
},
fnInitComplete: function(settings, json) {
//If ajax request was not made (when self.preventDataRequest == true), then self.dataTable equalls undefined here and results in "oDT is undefined error"
self.dataTableFixedColumns = new FixedColumns(self.dataTable, {
...
});
},
}) [/code]
This discussion has been closed.
Replies
Allan