Cannot read property 'sWidth' of undefined
Cannot read property 'sWidth' of undefined
I'm getting this error when the no.of columns changes. I call the LoadGrid method with 3 columns first. It works perfectly fine but when I call it again with new Data (having only 2 columns/objects) it throws this error. Also it doesn't update column headers. Instead stick with the previous 3 columns. Is there something we need to do when no.of columns changes? Do we have to notify the dataTable? Please help
function LoadGrid(tableId, gridData) {
var pageCount = 0;
var columnKeys = [];
if (gridData != null) {
pageCount = gridData.length;
for (var k in gridData[0]) {
columnKeys.push({ "data": k });
}
$(tableId).dataTable().fnClearTable();
$(tableId).dataTable({
"autoWidth": false,
"fixedHeader": false,
"searching": true,
"pageLength": pageCount,
"bDestroy": true,
"bSort": false,
"scrollY": 450,
"scrollX": true,
data: gridData,
columns: columnKeys
});
}
}
Calling LoadGrid by passing the tableId
LoadGrid("#tblActivitySummary", object.ActivitySummary, false); // object.ActivitySummary length is 3
When I call it again with different data I get error
LoadGrid("#tblActivitySummary", object.ActivitySummary, false); //object.ActivitySummary length is 2
Cannot read property 'sWidth' of undefined
Answers
Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.
Information on how to create a test page, if you can't provide a link to your own page can be found here.
Thanks,
Allan