Use same number format in DT *and editor
Use same number format in DT *and editor
I have a custom renderer for a numeric column:
render: DataTable.render.number('.', ',', 3),
Is it possible to apply the same format in a transparent way to the editor?
A rendered value like "1.200,1234" is rendered in the editor as "1200.1234" (which confuses the users).
It's the same issues when you look at the example https://editor.datatables.net/ for Salary.
What is the best approach here from transferring float values from the backend to the frontend, rendering and editing properly in a custom format and sending them back as float upon save?
Answers
You could use formatters for that -
fields.getFormatter
andfields.setFormatter
. There's an example on the reference page for dates, but you could do something similar for the number locale.Colin
You might also want to consider using a plug-in such as this one to format the data in the
input
. I wrote a plug-in for that to work with Editor a while back - you can get it here.The advantage of using a masking plugin like that is that it makes it harder for the user to screw up inputs such as
1,000,000
becoming1,0,00
which might prove difficult to validate.Allan