Bug sending iDisplayStart with bServerSide and bStateSave

Bug sending iDisplayStart with bServerSide and bStateSave

stratmanstratman Posts: 1Questions: 0Answers: 0
edited April 2010 in Bug reports
When you have bStateSave and bServerSide true, the iDisplayStart value sent to the server is always zero when you first load a page, ignoring the iStart value in the cookie.

I have confirmed that _fnLoadState() is in fact correctly loading oSettings._iDisplayStart from the cookie.
However, other functions after _fnLoadState(), but BEFORE _fnAjaxUpdate() are setting oSettings._iDisplayStart to zero.

Two examples where this is incorrectly occurring are: _fnFilterComplete() and _fnSort()

Let me know if this isn't clear, or if you need more information.

I have not yet looked for a solution, since I am not familiar with the inner workings of this plugin. I am hoping somebody more familiar will be able to quickly see a solution/oversight and patch it.
I'll post an update if I get around to digging into it though.

Replies

  • bjtbjt Posts: 4Questions: 0Answers: 0
    hi,

    i have exactly the same problem or bug.
    can anyone solve this problem?
  • bjtbjt Posts: 4Questions: 0Answers: 0
    i have an quick hack.
    it worked for me.
    # stratman can you test it too?

    this is my jquery.dataTables.js -> Version 1.6.2

    http://stashbox.org/855615/textupload.txt

    watch at line 2682-2684
    watch at line 2693
    watch at line 4631

    i have added some new code in this lines. with this code i think the problem is solved.
    a feedback would be great
  • MorriganMorrigan Posts: 10Questions: 0Answers: 0
    edited April 2010
    Hmm I think this is the same problem I describe on point 1) of my post here:
    http://datatables.net/forums/comments.php?DiscussionID=1724&page=1

    In any case, bjt's patched file does fix my problem. :)
  • MorriganMorrigan Posts: 10Questions: 0Answers: 0
    On second thought, with bjt's file, if I cleared the cookies and tried again, I got this Javascript error:

    _myStartVar is not defined
    /js/jquery.dataTables.js
    Line 2682
  • bjtbjt Posts: 4Questions: 0Answers: 0
    edited April 2010
    @ all
    the min js file is attached at:
    http://stashbox.org/856695/min.js
    readable file:
    http://stashbox.org/856729/readable.js

    @all
    Morrigan is right. The called error is there if there is no coockie alive

    _myStartVar is not defined
    /js/jquery.dataTables.js
    Line 2682

    You can fix this error when you set this var empty before you call the datatables
    Like this:
    (I know there is a better way but i only want to do a quick fix ;-) )
    [code]
    //the following line fixed the error: _myStartVar is not defined
    _myStartVar = 0;
    $(document).ready(function() {
    $('#example').dataTable( {
    "bJQueryUI": false,
    "sPaginationType": "full_numbers",
    "aaSorting": [[ 0, "desc" ]],
    "oLanguage": {
    "sProcessing": "Processing",
    "sLengthMenu": "_MENU_ Einträge pro Seite",
    "sZeroRecords": "Keine Einträge vorhanden.",
    "sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen",
    "sInfoEmpty": "0 bis 0 von 0 Einträgen",
    "sInfoFiltered": "
    (gefiltert von _MAX_ Einträgen)",
    "sInfoPostFix": "",
    "sSearch": "Schnellsuche",
    "sUrl": "",
    "oPaginate": {
    "sFirst": "Erster",
    "sPrevious": "Zurück",
    "sNext": "Nächster",
    "sLast": "Letzter"
    }
    },
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "/libs/jquery_grid/server.php?exit=1",

    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    "bAutoWidth": false
    ,"sDom": '<"top"lip>rt<"bottom"ip<"clear">'//lf
    ,"bStateSave": true
    ,"iDisplayLength": 50
    } );
    } );
    [/code]
  • bjtbjt Posts: 4Questions: 0Answers: 0
    if someone find an error you can write it down here.
    i watch this thread and i tried to fixed it then
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Hi all,

    I've got a fix for this now. I'll be distributing it as part of DataTables 1.7, but until then what you can do is replace the following block in _fnDraw:

    [code]
    oSettings._iDisplayStart = (oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
    0 : oSettings.iInitDisplayStart;
    [/code]
    with:

    [code]
    oSettings._iDisplayStart = (!oSettings.oFeatures.bServerSide &&
    oSettings.iInitDisplayStart >= oSettings.fnRecordsDisplay()) ?
    0 : oSettings.iInitDisplayStart;
    [/code]
    The reason for the bug is that fnRecordsDisplay() is 0 before data has been loaded from the server - and as such the code would always set the initial starting point to 0 as a (rather rubbish) sanity check.

    Regards,
    Allan
  • Mr PinkMr Pink Posts: 1Questions: 0Answers: 0
    Allan,

    I don't think the fix you suggest in your last post is enough.
    In function _fnDraw(), a few lines after the fix you suggest, there is the following block of code that resets iStart to 0 anyway:

    [code]
    if ( oSettings.oFeatures.bServerSide )
    {
    iStart = 0;
    iEnd = oSettings.aoData.length;
    }
    [/code]

    So therefore, I didn't find any way to overcome this bug. But actually, it seems to be the only one left, which makes you code way less buggy than mine !!!

    Thanks for this great plug!
  • medSwamedSwa Posts: 22Questions: 0Answers: 0
    edited February 2012
    is there a solution for this. Alan i tried using your fix but dint solve the issue. i use version 1.8.2. Any help
This discussion has been closed.