fiduswriter / simple-datatables

DataTables but in TypeScript transpiled to Vanilla JS
Other
1.38k stars 249 forks source link

Set search term inside search box when using `search()` #398

Open Stoakes opened 2 weeks ago

Stoakes commented 2 weeks ago

Hello,

Is your feature request related to a problem? Please describe. When using [search](https://fiduswriter.github.io/simple-datatables/documentation/search()),

Example: The user browses to a page displaying a list of enterprise and their category (health, building, tech ...). This page always returns the entire list, but by adding ?category in the url, js uses search() to filter out on client side the enterprises which don't belong to matching category. But there's no easy way, to remove this filter, if eventually user wants to display the entire list of entreprises.

Describe the solution you'd like

It would be awesome if the search term was directly added inside the search box, so that user can remove the predefined search.

Another solution coulkd be something like https://datatables.net/reference/option/search.search, where we can set the initial term in search options.

Describe alternatives you've considered I looked through the demo for filter and it seems to me, that it can't be tuned to match expected behaviour.

Thanks

rlafuente commented 1 week ago

While this issue persists, a workaround is to set the search box value with JS:

document.querySelector('.datatable-input').value = searchText;

where searchText would contain the search string.