Use same number format in DT *and editor

Use same number format in DT *and editor

ajungajung Posts: 14Questions: 5Answers: 0

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

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    You could use formatters for that - fields.getFormatter and fields.setFormatter. There's an example on the reference page for dates, but you could do something similar for the number locale.

    Colin

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    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 becoming 1,0,00 which might prove difficult to validate.

    Allan

Sign In or Register to comment.