Change some words in cells
Change some words in cells

Hi everyone,
first of all: sorry for my english.
I made a table that retrieve data from a json.
I have 2 version of the table for 2 languages and the translation of headers and other elements wasn't a problem.
However i can't find a way to translate some words taken by the json.
For example i need to translate "Scad: 02-11-2021 | Pot.Rend.: 34.14 %" to "Expiry: 02-11-2021 | Pot.Return: 34.14 %", so only the words "Scad" and "Pot.Rend" needs to be translated.
I tried renderer, celldata, jquery and javascript solutions but i was unable to perform the task.
My code looks like this:
"ajaxSource": "SOURCE",
"columnDefs": [
{ "visible": false, "targets": 0 }
],
"displayLength": 9999,
"columns": [
{ "data": "KeyID" },
{ "data": "ISIN" },
{ "data": "Sottostante", "width": "10%" },
{ "data": "Strike" },
{ "data": "Last" },
{ "data": "Performance" },
{ "data": "Capitale" },
{ "data": "AltreInfo", "width": "30%" },
{ "data": "Scheda" }
],
In this example "AltreInfo" is the column to target.
Anyone willing to write a piece of code that i can use? I'm not an expert at all, so please be kind.
Thank you very much.
This question has an accepted answers - jump to answer
Answers
You can do this on the server with a getFormatter (search the docs for getFormatters). Or you can do it client side as well.
Client side you can just use "replace": https://www.w3schools.com/jsref/jsref_replace.asp
Please take note of this:
So if you need to replace multiple Scads and Pot.Rends in one string you'll need a regular expression.
Thank You so much for this!
I looked for the replace function but i did some syntax error and didn't work.
I spent hours trying to figure it out and then you came and saved me.
Just for completeness, this is the piece of code that did the trick (i removed the lang var and added "" to data.
Again big, big thank you.
May i donate something for your help? Let me know.
I am glad that you got it working! I am just a user of Editor and Data Tables, but I think the author of Data Tables and Editor, Allan Jardine, and his team deserve additional support. Please use this page for your donation by purchasing one of the supporter packages. Many thanks!
https://datatables.net/purchase/index
Done!
Sorry to bother again...
I have problems with special characters.
I'm unable to change "Periodicità" in "Periodicity".
Tried html and unicode, too, but both didn't work.
Is there a solution for this?
Thanks
Interesting. It works no problem using Javascript. I did it with the W3 schools tool. You have the link above and "Periodicità" was replaced without any problem:
You can try escaping special characters.
https://www.freeformatter.com/html-escape.html#ad-output
If I try the replacement with an escaped value it doesn't work though:
I would try to find a solution by googling or searching Stack Overflow. Good luck.
Yes i tried with
à
but didn't work.I'll try to find a solution and i'll be report it here if found.
Thanks again!
Ok I found the solution!
The page encoding was missing.
<meta charset="utf-8">
This fix the problem.