[SearchPanes]: Invalid pane options are still restored when serverSide: true (e.it #314)

[SearchPanes]: Invalid pane options are still restored when serverSide: true (e.it #314)

pgerundtpgerundt Posts: 90Questions: 13Answers: 2

In addition to:
https://datatables.net/forums/discussion/72231/invalid-searchpanes-options-should-not-be-restored-from-statesave#latest
here is an updated test case:
http://live.datatables.net/coduluva/14/edit?js,output

@sandy 's fix works fine, but not if serverSide: true is set.

Steps to reproduce:
- Open search panes and select filter for first name "Alina" -> one row is displayed
- Reload page -> one row is displayed
- Click on "Simulate edit" ("Alina" is now renamed to "Alina_Modified") -> "No matching records found." (filter "Alina" is still set, causing no matches)
- Open search panes again -> one row is displayed

I guess SearchPanes should unset any filters if the filter value is no longer present in the Ajax response.

Replies

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Here is another test case for using the dom option P instead of B:

    http://live.datatables.net/dolokuyo/1/edit?js,output

  • allanallan Posts: 57,699Questions: 1Answers: 9,195 Site admin

    Hi,

    You need to tell SearchPanes that the edit has happened. It doesn't listen automatically for the data being reloaded on the table. That can be done with the searchPanes.rebuildPane() function:

        dataTable.ajax.reload(() => {
            dataTable.searchPanes.rebuildPane(undefined, true);
        });
    

    http://live.datatables.net/dolokuyo/7/edit

    Regards,
    Allan

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Hi @allan,

    I'm sorry, my test case was misunderstandable.

    Imagine having a classic CRUD application:
    - You have a list page with DataTables and filter the list for the firstname "Alina"; only one row is displayed; the filter setting is saved
    - You click on an edit button and change poor "Alina" to something different ("Alina_modified")
    - You return to the list page, the (invalid) filter settings are loaded and you end up with an empty DataTables list

    That's what the "Simulate edit" button is trying to show :)

    Regards,
    Pascal

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Hi @allan,

    can you confirm this is a bug?

    Regards,
    Pascal

  • allanallan Posts: 57,699Questions: 1Answers: 9,195 Site admin

    Hi Pascal,

    No, I don't think it is actually. The state was saved with "Alina" being the filter applied. If you then restore the state, you are restoring "Alina" as the store to be applied - not the newly modified value.

    Consider for example you had three people called "Alina" - edit one of them, then come back and the filter should show two people called "Alina" now. That is just the same as what is happening.

    We could consider adding an option to remove any filter which is applied and no longer has any entries in the table, but that in turn could be considered a bug if one were expecting the filter to still be applied.

    Allan

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Hi @allan,

    I totally agree with you. Saved filters should be applied even if resulting in 0 rows.

    The problem is:
    Filter "Alina" is saved, comes back and is applied to the table - now having 0 rows.
    But the search panes button says "number of filters applied: 0" and you cannot unselect your filter selection "Alina" and you cannot clear all filters.

    See here:
    http://live.datatables.net/coduluva/14/edit

    Or should the serverside script return the search pane option "Alina" with total = 0 and count = 0?

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Hi @allan,

    got it working. The serverside script simply has to return all selected options from the request variable searchPanes with count and total set to 0.

    Thanks,
    Pascal

  • allanallan Posts: 57,699Questions: 1Answers: 9,195 Site admin

    Ah I see - sorry I had misunderstood. Good to hear you got it working.

    Allan

Sign In or Register to comment.