bInfinite and loading from serverside
bInfinite and loading from serverside
First of all, I greatly appreciate Datatables! Currently I use in a program needs to get a Desktop look & feel and Datatables is a great step in accomplishing this. Currently I have a table with 1800 rows that is filled server side via a custom searchData function. The table fills itself on initialization completely, meaning a long waiting time and slow browser response. It would be great if it would be filled with 50 rows first and then later while scrolling would load more rows if necessary.
This is the main slice of code, I am willing post more, but I don't want to clutter this post to much and I believe this is most of the relevant code. 'fillTable' is called during the 'document ready event' of JQuery and contains JSON data for the first rows so Datatables can immediately start calculating column widths. Only searchTable interferes with the requests that that Datatables sends to the server. Serverside I receive '-1' as iDisplayLenght variable. I hope someone sees where that problem does come from.
[code]
function fillTable(data)
{
data = defaultSetupValues(data);
overviewTable.dataTable(data);
}
function defaultSetupValues(data)
{
data.iDisplayLength = defaultListLength; // Default 50 items
data.bLengthChange = false;
data.bStateSave = true;
data.bPaginate = false;
data.bInfo = false;
data.sScrollY = calculateTableHeight();
data.bScrollInfinite = true;
data.bScrollCollapse = false;
data.aaSorting = [[1, "asc"]];
data.sDom = "lrt";
data.fnRowCallback = function(nRow, aData, iColPos, iColTotalPos) {return newRow(nRow, aData, iColPos, iColTotalPos);};
data.fnFooterCallback = function(nFoot, aasData, iStart, iEnd, aiDisplay) {drawFooter(nFoot, aasData, iStart, iEnd, aiDisplay);};
data.fnDrawCallback = function() {/*paginate();*/loadContextMenu(); adjustFooterWidth(); };
data.fnInitComplete = function() {adjustFooterWidth(); };
data.bProcessing = true;
data.bServerSide = true;
data.sAjaxSource = urlAjaxSource;
data.fnServerData = searchTable;
return data;
}
function searchTable( sSource, aoData, fnCallback )
{
if(!searchDisabled)
{
aoData.push({"name": "columnToIndex", "value": columnIndex});
if(columnIndex.length == 0) columnToIndexCalculate();
filterDataArray = new Array();
for(var i in filterData)
{
filterDataArray.push(new Array(filterData[i][0], filterData[i][1]));
}
//filterDataArray.push(new Array("addressTypeId", $("#addressTypeSelect").val()));
aoData.push({"name": "filterData", "value": filterDataArray});
searchData = aoData;
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback});
}
}
[/code]
This is the main slice of code, I am willing post more, but I don't want to clutter this post to much and I believe this is most of the relevant code. 'fillTable' is called during the 'document ready event' of JQuery and contains JSON data for the first rows so Datatables can immediately start calculating column widths. Only searchTable interferes with the requests that that Datatables sends to the server. Serverside I receive '-1' as iDisplayLenght variable. I hope someone sees where that problem does come from.
[code]
function fillTable(data)
{
data = defaultSetupValues(data);
overviewTable.dataTable(data);
}
function defaultSetupValues(data)
{
data.iDisplayLength = defaultListLength; // Default 50 items
data.bLengthChange = false;
data.bStateSave = true;
data.bPaginate = false;
data.bInfo = false;
data.sScrollY = calculateTableHeight();
data.bScrollInfinite = true;
data.bScrollCollapse = false;
data.aaSorting = [[1, "asc"]];
data.sDom = "lrt";
data.fnRowCallback = function(nRow, aData, iColPos, iColTotalPos) {return newRow(nRow, aData, iColPos, iColTotalPos);};
data.fnFooterCallback = function(nFoot, aasData, iStart, iEnd, aiDisplay) {drawFooter(nFoot, aasData, iStart, iEnd, aiDisplay);};
data.fnDrawCallback = function() {/*paginate();*/loadContextMenu(); adjustFooterWidth(); };
data.fnInitComplete = function() {adjustFooterWidth(); };
data.bProcessing = true;
data.bServerSide = true;
data.sAjaxSource = urlAjaxSource;
data.fnServerData = searchTable;
return data;
}
function searchTable( sSource, aoData, fnCallback )
{
if(!searchDisabled)
{
aoData.push({"name": "columnToIndex", "value": columnIndex});
if(columnIndex.length == 0) columnToIndexCalculate();
filterDataArray = new Array();
for(var i in filterData)
{
filterDataArray.push(new Array(filterData[i][0], filterData[i][1]));
}
//filterDataArray.push(new Array("addressTypeId", $("#addressTypeSelect").val()));
aoData.push({"name": "filterData", "value": filterDataArray});
searchData = aoData;
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback});
}
}
[/code]
This discussion has been closed.
Replies
I'm afraid I don't quite follow - if you are using server-side processing, DataTables will request and show only the records which are needed for each page. If you have iDisplayLength as -1, then it will send that, meaning to show all - is that the issue you are seeing? Is there a reason to show all, rather than just let it go page by page, particularly if you are using infinite scrolling (like this: http://datatables.net/examples/basic_init/scroll_y_infinite.html ).
Allan
I dug into it a lot deeper today and somehow the object aoData that is send to my searchTable is always containing iDisplayLength = -1, though the defaultListLength is 50. Therefore infinite scrolling doesn't seem to work and the table always gets completely populated instead of filled on scrolling.