fiduswriter / simple-datatables

DataTables but in TypeScript transpiled to Vanilla JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Search via code

shaunroselt opened this issue · comments

Is there a way I can search via code?

I'm currently selecting the input search box and then changing the value of it and this works perfectly fine, but then how do I trigger the search function in order to actually search through the table?

I tried by triggering the keyup event on the table, but that's not working. The table results doesn't change.

Here's my code:

const SearchBoxSelector = `#MyTable .dataTable-input`;
document.querySelector(SearchBoxSelector).value = "Hello";
document.querySelector(SearchBoxSelector).dispatchEvent(new Event("keyup"));

Any idea on how to trigger the search without actually calling the dataTable directly?

https://fiduswriter.github.io/simple-datatables/documentation/search()

Please read the documentation and take a look at demos before posting issues.

I did take a look at that page and other documentation before posting an issue and I couldn't find a solution.

That page you sent uses the dataTable directly as can be seen by this line of code: datatable.search(term, columns);

I am looking for a way to trigger the search event without directly using/calling it from the dataTable instance.

So that's where I had the idea of trying to trigger the keyup event on the search box, but that doesn't seem to work.

Are you referring to a specific demo? Or just demos in general?

@shaunroselt In version 7.3.0, I listen for the input event on the wrapperDom. I am listening there as there could be multiple search fields. Maybe that helps you?

Hmmm. That does help a little.

I will need to play with 7.3.0 and check.

Thank you for the extra info.

Hey @johanneswilm

I've finally had some time to have a look at this issue again.

What do you mean by the wrapperDom?

Can you show me a code example of what I need to select and trigger the input event on please?

@shaunroselt unfortunately I don't have the time to make full demos for individual support requests given that there are so many and I'm doing this as a volunteer. But if you make a fulling working minimal example on ha fiddle e using a current version of this library, I'll yake a look and gice a hint of what you need to change if it is not yet documented or can be foubd in one of the demos.