Multi filter select and saveState

Multi filter select and saveState

mducharmemducharme Posts: 2Questions: 1Answers: 0

Hello, I am having a problem with the multi-filter select example (https://datatables.net/examples/api/multi_filter_select.html) and saveState. I cannot seem to find someone else with the same problem anywhere.

I have the multi-filter select working - I am really only using it for a filter for one column so it is slightly modified.

If I enable saveState, and navigate away from the page and back, everything works except the filter drop down <select> now only contains the filtered items instead of showing all items. As a result it is impossible to change the filter to anything else because if you chose an item, navigated away and navigated back, that item is now the only thing you can choose in the drop down list.

I have searched everywhere to try to figure out how to get it to show all items and cannot find the solution.

At this code:

                column.data().unique().sort().each( function ( d, j ) {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );

column.data().unique().sort() is only returning the filtered records. How can I get it to return all records regardless of the current filter applied?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @mducharme ,

    column.data().unique().sort() is only returning the filtered records. How can I get it to return all records regardless of the current filter applied?

    It should return everything, it isn't affected by the filtering on the table. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • mducharmemducharme Posts: 2Questions: 1Answers: 0

    Hi @colin

    Thanks - I think I may have figured out where the problem is. I am using serverSide: true - it seems like the AJAX data query is therefore being limited to the search query and is having the side effect of eliminating the filtered records from the column.data().unique().sort() results. Would that explain it?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @mducharme ,

    Yep, exactly that. When you've got serverSide enabled, the client is only aware of the data last returned by the server.

    Cheers,

    Colin

This discussion has been closed.