Disabling bFilter breaks the Pagination SaveState

Disabling bFilter breaks the Pagination SaveState

choopeschoopes Posts: 2Questions: 0Answers: 0
edited November 2009 in Bug reports
I've got a grid set up with the filter turned off and using the full numbers pagination type with savestate on. As it is right now, the savestate will remember which column you're sorting by and which direction but it will not recall the page you were last on. The initialization initialization options look like this, but if I set bFilter to 'true' the Pagination SaveState resumes working only with the filter displayed:

[code]
$(document).ready(function() {
$('#tblSort').dataTable( {
"bPaginate": true,
"bLengthChange": false,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"bStateSave": true,
"sPaginationType": "full_numbers",
"sDom": '<"top"ip>rt<"bottom"fl><"clear">',
"aoColumns": [
null,
null,
null,
null,
null,
{ "bSortable": false },
null,
{ "bSortable": false }
]
} );
} );
[/code]

I'm not sure why turning the filter off kills the Pagination savestate but that seems to be the case. Tested in Firefox 3.5 and IE6.

e: removing the filter from sDom is a valid workaround but it still seems to be a bug

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi choopes,

    Very good bug! Thanks for taking the time to report it. The issue is indeed related to the enablement status of the filtering, which is not a particularly good state to be in... The problem was that my handling for the code which relates to restoring the page position was only executed when filtering was enabled. Rather than getting into the sticky situation of having the same code duplicated for sorting, filtering and neither of them, I've put it into fnDraw, which now kicks off like this:

    [code]
    function _fnDraw( oSettings )
    {
    var i;
    var anRows = [];
    var iRowCount = 0;
    var bRowError = false;
    var iStrips = oSettings.asStripClasses.length;
    var iOpenRows = oSettings.aoOpenRows.length;

    /* If we are dealing with Ajax - do it here */
    if ( oSettings.oFeatures.bServerSide &&
    !_fnAjaxUpdate( oSettings ) )
    {
    return;
    }

    /* Check and see if we have an initial draw position from state saving */
    if ( typeof oSettings.iInitDisplayStart != 'undefined' && oSettings.iInitDisplayStart != -1 )
    {
    oSettings._iDisplayStart = oSettings.iInitDisplayStart;
    oSettings.iInitDisplayStart = -1;
    _fnCalculateEnd( oSettings );
    }
    [/code]
    And the section which does the redraw in _fnFilterComplete now looks like:

    [code]
    /* Redraw the table */
    oSettings._iDisplayStart = 0;
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );
    [/code]
    I believe that will fix the issue for you, and it will be available in the next release of DataTables (1.5.5).

    Regards,
    Allan
  • choopeschoopes Posts: 2Questions: 0Answers: 0
    Looks like that will work! Thanks for the quick reply and I'm glad I could contribute in some small way. DataTables helped us out immensely this week.
  • soberspsobersp Posts: 28Questions: 0Answers: 0
    HI Allan

    This is a good Fix. I am using DataTables 1.5.3.

    I just added Pagination. My DataTables calles fnDraw every 5 secs to get the latest data.
    Initially Pagination was not working, It always defaulted to 1st Page on fnDraw

    Then I used fnPageChange()- Set it Back to the current page i navigated to, which fixed pagination but then the Filter and Sorting was resetting on fnDraw().

    Then I made the above change in "fnFilterComplete ", the Filter and Sorting where good, but Pagination always agani defaulted to Page 1;

    So I sued the above version
    /* Redraw the table */
    //oSettings._iDisplayStart = 0;
    _fnCalculateEnd( oSettings );
    _fnDraw( oSettings );

    W/o Setting the _iDisplayStart back to zero and it works good,,,,

    Is there any specific reason you are setting it back to 0, ?

    Sobers
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Hi Sobers,

    Yes, the reason for it is that when the end user is filtering, they would generally expect to go back to the start. For example say I'm on the 10th page of a table and then think "I'll try filtering for 'Allan'" (or whatever...), you start typing, but what's the good in remaining in the middle or at the end of the table, when the information that is being presented has completely changed. Hence the reset back to zero :-)

    Method to the madness :-)

    Hope this explains it.

    Regards,
    Allan
  • soberspsobersp Posts: 28Questions: 0Answers: 0
    edited November 2009
    Actually I was just replying to my Post...

    I figured that out when I ran into one of such Scenario, But you are using the same method
    _fnFilterComplete() on fnDraw, which resets the Pagination to Page 1.

    Anyways I moved the "oSettings._iDisplayStart = 0;"
    to

    function _fnFilter( oSettings, sInput, iForce, bEscapeRegex )

    and it works as expected

    Thanks very Much

    Sobers
This discussion has been closed.