Filtering on hidden column defeated by new sort-- how to reenable?

Filtering on hidden column defeated by new sort-- how to reenable?

atlas3650atlas3650 Posts: 11Questions: 0Answers: 0
edited June 2009 in General
Hi,

I have filtering on hidden columns, driven by a dropdown menu, implemented and working very well. However, when you choose to resort the (filtered) entries, the filtering is dropped and all entries reappear.

It looks like the callbacks don't really fit the bill for addressing this, because if I use fnDraw callback, there'll be a second where the entire, unfiltered table is still visible before I filter again.

Any suggestions welcomed.

Thanks!

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Hi atlas3650,

    I'm not seeing this problem with my multi-column filtering example: http://datatables.net/examples/example_multi_filter.html

    What should happen is that DataTables will cache the filter for each individual column, and for the global filter, and then reapply that information once a sort has occurred. I sort of vaguely remember a bug about this a long while back, but the current 1.4 and 1.5 (beta) releases don't appear to be showing this problem. Could you post any more information (ideally with a link showing the problem)?

    Thanks,
    Allan
  • atlas3650atlas3650 Posts: 11Questions: 0Answers: 0
    Allan,

    I figured out the issue. I used bFilter=false because I don't want the "search" box to appear (filtering is done through the API via a dropdown menu). If bFilter''s false though, dataTables doesn't resort after changing the sort order. Is there a way to get the best of both worlds?

    Thanks.
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Hi,

    So you want filtering support (i.e. fnFilter()) but not the text box? Yup - no problem there. What you need to do is use the sDom option ( http://datatables.net/usage#sDom ) and drop the 'f' option from the string. This will cause DataTables to not insert the filtering input into the DOM, but it will have all it's internals required for filtering switched on :-)

    Allan
  • atlas3650atlas3650 Posts: 11Questions: 0Answers: 0
    edited June 2009
    OK, I got it, for other users' reference, you can do something like the following:

    [code]
    var commentTable = $('#commentsBlock #commentsTable').dataTable( {
    "bFilter" : true,
    "bInfo" : false,
    "bLengthChange" : false,
    "sDom" : 'itp',
    "bPaginate" : false,
    "aoColumns" : [ { "bVisible" : false }, // potentialAnswerId
    { "bVisible" : false }, // group name
    { "bSortable" : true }, // date
    { "bSortable" : true }, // comment
    { "bSortable" : true } // useful?
    ]
    } );
    [/code]

    In the above, filtering is enabled, but I only want dataTables to render the info text, the table itself, and the paginator, so there's no 'f' in the sDom string I pass in for that param.

    Thanks, Allan, you rock.
  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Hi,

    That's great, thanks for posting your code. One thing to note is that you don't actually need to have "bFilter": true, since this is the default value. But then given that the filtering isn't in the sDom, there is no harm in being verbose :-)

    Regards,
    Allan
  • kolokgkolokg Posts: 1Questions: 0Answers: 0
    Thank you guys!

    I had a very similar problem and that thread fixed it,

    Thanks,
    Gabor
This discussion has been closed.