All row displaying on initialisation

All row displaying on initialisation

briangalbriangal Posts: 5Questions: 0Answers: 0
edited August 2011 in DataTables 1.8
Hey,

I using an Ajax request to get the initial row and column data

I'm using sAjaxSource to do my server side processing.

I'm also using iDeferLoading as I only want my "sAjaxSource" to trigger for filtering / sorting etc

I've got 26 rows in total and displaying 5 with pagination enabled by default.

The issue i'm having is that all 26 rows are being displayed on initial load.

Interestingly I still get - Showing '1 to 5 of 26 entries' at the bottom of the table

iDeferLoading seems to be working ok getSubsetData does not get triggered

Commenting out "bServerSide": true and "sAjaxSource": "${request.contextPath}/table/getSubsetData" fixes the issue

Here's my code:

[code]
$(document).ready(function() {
$.ajax( {
"dataType": 'text',
"type": "GET",
"url": "${request.contextPath}/table/getTableData?tableType=basic",
"success": function (dataStr) {
var data = eval( '('+dataStr+')' );
$('#example').dataTable({
"aaData": data.aaData,
"aoColumns": data.aoColumns,
"iDisplayLength": 5,
"iDeferLoading": 26, //todo: 26 is total number of rows - needs to be dynamic
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "${request.contextPath}/table/getSubsetData"
});
}
} );
});
[/code]

Replies

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    How are you generating the HTML table? I would guess that loop is outputting all 26 rows. When you enable deferred loading, DataTables will take no action on the initial page display (since it has been deferred).

    With 26 rows only, you'd be as well just using the data loaded from the DOM I would say. Server-side processing only really becomes interesting when you are dealing with many thousands or millions of rows.

    Allan
  • briangalbriangal Posts: 5Questions: 0Answers: 0
    My requirement is to draw an initial table, rows and column headers, from JSON object returned from the server. Hence, the initial ajax call.

    Using this data I wanted to initialize the table i.e.

    [code]
    "aaData": data.aaData,
    "aoColumns": data.aoColumns,
    [/code]

    This works fine, even with "iDeferLoading" set.

    The only HTML I'm using is:

    [code]


    [/code]

    When I include the following

    [code]
    "bServerSide": true,
    "sAjaxSource": "${request.contextPath}/table/getSubsetData"
    [/code]

    I then get the pagination issue described above.

    The 26 rows is just test data, potentially we have thousands of rows to deal with.

    hope this makes sense....
  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Yup perfect sense. What is data.aaData.length? Is it 26 or 5? I'm guessing 26 since DataTables needs to be getting the 26 rows from somewhere - if you want just 5 rows to be shown, you need to give it the five rows that would be shown in the first page.

    Allan
  • briangalbriangal Posts: 5Questions: 0Answers: 0
    Hey allan,

    Ye, its 26. I understand what i need to do now, thanks. The processing of the rows needs to be done on initialization when using serverSide and ajaxSource and not just when filtering, sorting etc.
This discussion has been closed.