datatables.js Editor - Replace character in string on create/update

53 views Asked by At

Using datatables.js Editor, I want to replace a character, a semicolon, with &#x3b; when data is submitted to the database.

I am told that this can be done with the setFormatter function:

https://editor.datatables.net/manual/php/formatters

How would I do this? Example would be great.

NOTE: The editor is the PHP API version

1

There are 1 answers

0
Wh1t3rabbit On BEST ANSWER

The documentation you linked to is for the PHP API, but your question is not tagged with PHP. Assuming you are indeed using PHP you can use str_replace to replace one character with another.

Field::inst( 'your_field_name' )->setFormatter( function ( $fieldValue, $rowData ) {
    return str_replace(';','&#x3b;',$fieldValue); //replace semicolon with html escape sequence
} )

Change your_field_name as needed.