table.state.clear() but keep Column ordering and pageLength

table.state.clear() but keep Column ordering and pageLength

memmememme Posts: 3Questions: 1Answers: 0

Hi,

I added a filter reset button to clear the filters with table.state.clear().

Unfortunately, it also resets the column ordering and the pageLength. How can I keep both options but clear all others?

Thank you very much

Regards

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    You can use order() and page.len() to get the current order before clearing the state then use those to set the order and length after the clear.

    Kevin

  • memmememme Posts: 3Questions: 1Answers: 0
    edited June 2022

    @kthorngren Thanks for reply, but it seems like its not working.
    My code:

    $('#reset-filter').on('click', function () {
    var $length= $('#blogDatatable').DataTable().page.len();
    $('#blogDatatable').DataTable().state.clear();
    $('#blogDatatable').DataTable().page.len($length).draw();
    window.location.reload();
    });

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    I see. That process isn't quite right, Maybe just use columns().search() with an empty string to clear all the column searches. Seems that is all that is needed:
    http://live.datatables.net/jexadexe/1/edit

    Kevin

  • memmememme Posts: 3Questions: 1Answers: 0

    Thanks!

    The solution with columns()search('') is working on chrome, but not on firefox....
    how to fix that?

Sign In or Register to comment.