[Bug/Problems] iDisplayStart get back to zero when we do sorting in 2,3,4 ... page

[Bug/Problems] iDisplayStart get back to zero when we do sorting in 2,3,4 ... page

hksdhksd Posts: 15Questions: 0Answers: 0
edited August 2012 in DataTables 1.9
Hi All,

Need Your Help Here...

I'm Using datatables with server side processing.. (using java , struts )
here is my js for datatables :
[code]
$(document).ready(function() {
oTable = $('#tables').dataTable({
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "POST",
"oLanguage": {
"sInfo": "_TOTAL_ items ",
"sInfoEmpty": "",
},
'aoColumns': [
{
"sWidth" : '70px',
"bVisible" : false
},
{
"sWidth" : '70px'
},
{
"sWidth" : '70px'
},
{
"sWidth" : '70px'
},
{
"sWidth" : '70px',
"bSortable": false,
"fnRender": function ( o, val ) {
return 'Edit';
}
},
{
"sWidth" : '70px',
"bSortable": false,
"fnRender": function ( o, val ) {
return 'delete';
}
}
],
'bAutoWidth': false,
'bFilter': false,
'bInfo': true,
'iDisplayLength': 10,
'sPaginationType': 'full_numbers',
"bLengthChange" : false,
"sAjaxSource": "jsonfieldsfeed!populate.action"
});


} );
[/code]
here is my problem :

fist time render the tables (database have 11 items / data ) , it send query string parameters are :
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
bSortable_4 false
bSortable_5 false
iColumns 6
iDisplayLength 10
iDisplayStart 0
iSortCol_0 0
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
mDataProp_2 2
mDataProp_3 3
mDataProp_4 4
mDataProp_5 5
sColumns
sEcho 1
sSortDir_0 asc

then go to next page (pagination to page 2) the query string parameters are :
bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
bSortable_4 false
bSortable_5 false
iColumns 6
iDisplayLength 10
iDisplayStart 10
iSortCol_0 0
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
mDataProp_2 2
mDataProp_3 3
mDataProp_4 4
mDataProp_5 5
sColumns
sEcho 2
sSortDir_0 asc

if we see the iDisplayStart value is 10. so it will set your sql query for limit to 10,10

we are now in the second page. now i'm sorting a column in the page 2. the weird think is iDisplayStart become 0 :

bSortable_0 true
bSortable_1 true
bSortable_2 true
bSortable_3 true
bSortable_4 false
bSortable_5 false
iColumns 6
iDisplayLength 10
iDisplayStart 0
iSortCol_0 1
iSortingCols 1
mDataProp_0 0
mDataProp_1 1
mDataProp_2 2
mDataProp_3 3
mDataProp_4 4
mDataProp_5 5
sColumns
sEcho 3
sSortDir_0 asc

it give wrong result sorting data because right now the limit sql query become 0,10.

can any one have solution for this issue ? how to handle sorting if the page is not in the first page?

Best Regards,

HKS

Replies

  • hksdhksd Posts: 15Questions: 0Answers: 0
    Hi all,
    any clue on this??
  • hksdhksd Posts: 15Questions: 0Answers: 0
    for the moment i use

    edit your jqueryDataTables.js after line 3895 or below this code :
    [code]
    3895 oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    [/code]

    change line of code 3896 :
    [code]
    3896 oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    [/code]
    to this code :
    [code]
    if(oSettings.iDraw == 0)
    oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    [/code]

    Best regards,
    HKS
  • hksdhksd Posts: 15Questions: 0Answers: 0
    we are edit function _fnSort ( oSettings, bApplyClasses )
    before :
    [code]
    /* Copy the master data into the draw array and re-draw */
    if ( oSettings.oFeatures.bFilter )
    {
    /* _fnFilter() will redraw the table for us */
    _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
    }
    else
    {
    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );
    }
    [/code]
    we changed it.. after
    [code]
    /* Copy the master data into the draw array and re-draw */
    if ( oSettings.oFeatures.bFilter )
    {
    /* _fnFilter() will redraw the table for us */
    _fnFilterComplete( oSettings, oSettings.oPreviousSearch, 1 );
    }
    else
    {
    oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
    if(oSettings.iDraw == 0)
    oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );
    }
    [/code]

    Best Regards,

    HKS
  • hksdhksd Posts: 15Questions: 0Answers: 0
    work on version 1.9.2

    Best regards,

    HKS
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This is intentional - it occurs when both client-side and server-side processing. When you click to sort, typically you will want to go to the start of the list, rather than ending up somewhere in the middle of it, with little reference). That is why it is setup to work this way by default.

    However, as you have found, it is easy to override in the source code, so if you don't want this behaviour, just modify the code as you have done :-)

    Allan
  • hksdhksd Posts: 15Questions: 0Answers: 0
    Hi Allan,

    I see....

    Thank you for the explaination.

    Best Regards,

    HKS
This discussion has been closed.