bInfinite and loading from serverside

bInfinite and loading from serverside

lleveringllevering Posts: 12Questions: 0Answers: 0
edited October 2010 in General
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]

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    Hi llevering,

    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
  • lleveringllevering Posts: 12Questions: 0Answers: 0
    Sorry I really missed your reply somehow. I still didn't solve the problem I had and by Googling I came across my own post.

    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.
  • lleveringllevering Posts: 12Questions: 0Answers: 0
    Searched further, when I manually overwrite the 'iDisplayLength' value in the searchTable function infinite scrolling starts functioning. However it is wrong on the iDisplayStart value as it thinks only 25 rows have been fetched already, but it are 50 rows in reality. Glad I got the first part working now, but now I really have to find a way to get all the numbers right.
  • lleveringllevering Posts: 12Questions: 0Answers: 0
    The basic code is quite old, so I saw that the fnServerParams function is now way to go when you want to add custom filters. This solves a lot of my issues, however currently only with iDeferLoading set bInfinite is working. If I do not set it, all records are loaded at once. Maybe I am missing something, but I haven't seen that value is required to let infinite scrolling work.
This discussion has been closed.