How to change the search language option dynamically
How to change the search language option dynamically
leninad69
Posts: 4Questions: 0Answers: 0
I've been trying without success to change the search language option of an already initialized/drawn datatable object ... as far as I understood it should be possible .. but I only get errors (not a function, undefined, uncaught,..).. any suggestion?
This discussion has been closed.
Replies
I do not know if there is a standard function for it, as I could not find one.
But you might try it the jQuery way, like this:
I do not know if this a good way to do, as you are changing the settings of an already initialized table and that last is not recommended.
Thank you Tester2017 ... your solution works great !!
Unfortunately if you use it, the search box does not work any more... you are right .. it is not a good idea to change settings of an initialized table ...
This is because the input is being replaced, along with it's event handers.
You could do something like this instead:
and turn it into a function if you want:
and call it with
changeSearchLabel("#YOUR_TABLE", "New Label Text");
Thanks rduncecb ... it works without any problem!
Alternatively to change the search label, per [this page] (https://datatables.net/manual/i18n "this page"), you can do this when initializing your table:
I use it to set the label to "" and instead put placeholder text into the search field.
Hi all,
after fight against the code for a while I have figured out a workaround until Allan implements something in the API to change settings language after initialization without have to destroy the table.
My table initialization is like:
As you see I load my language texts from a file by default in English. When the user change application's language I execute a javascript method to change whole texts in the application being the desired language the value of the selectedLanguage variable. Inside that method I use:
Works like a charm and change all the texts within the table.
Hi @Yllandra .
I've tried to replicate your second block of code to change the language dynamically but it does not work for me. Are you sure just passing table.draw() is enought to change the lang? I think I should pass an argument with the oLanguage var to the table instance.
I'm using 1.10.16 version.
Thanks.
Hi @jonalxh ,
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