Default search using preDefined searchBuilder configuration option is not correctly executed

Default search using preDefined searchBuilder configuration option is not correctly executed

LimpEmuLimpEmu Posts: 72Questions: 20Answers: 1

Link to test case: https://live.datatables.net/hudarabu/1/
Debugger code (debug.datatables.net): n/a
Error messages shown: n/a
Description of problem:
I would like to load a predefined search when the user first requests a table, but the search is not fully loaded. It shows the data and condition correctly, but the value box shows as empty even though the value that is specified in the predefined search exists in the data (and is forced to always exist).

I set up the example exactly the way I need it, i.e., initially the page is loaded with an empty table. The data is then loaded in the table when the user clicks on a button. Therefore, to see that this is not working, after the page has loaded, click on the button Replace Data at the very top. At this point, the table should only show 1 line, the one for which the Time Unit is "ALL". The search criteria are not completely loaded though and all rows are shown. The search criteria appear to not populate the value box with the options based on the data.

I tried to initially work the example with other data just to give a simplified example, but with my simplified data the feature worked just fine, so it's something about my table that appears to cause this issue.

Please let me know what I am doing wrong. Thank you, Beate

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    It seems like the searchBuilder.preDefined configuration is only applied if the table has table data. I updated the test case to load some of the data on initialization:
    https://live.datatables.net/binehoti/1/edit

    After clicking the Reload Data button the table is still filtered by the predefined search. It might be a bug that it is not applied if the Datatable if the initial table is empty. @allan will need to comment on this.

    As a workaround use searchBuilder.rebuild(). I added this to the test case to reapply the predefined filter:

    table.searchBuilder.rebuild( table.searchBuilder.getDetails() );
    

    After the `-api rows.add()1. See this test case:
    https://live.datatables.net/tikifacu/1/edit

    Kevin

  • LimpEmuLimpEmu Posts: 72Questions: 20Answers: 1

    Thank you, Kevin!
    Your suggestion makes sense, and I should have thought of that since searchBuilder.rebuild() is also used by the buttons above the table. I like your solution better than my work-around which replaced "=" with "contains".
    I appreciate your help!
    Beate

Sign In or Register to comment.