Edit numeric field as per decimal/thousand separator settings

Edit numeric field as per decimal/thousand separator settings

debduttacdebduttac Posts: 9Questions: 2Answers: 0

Hi,

I am implementing DataTables and Editor plugin using javascript/jQuery in our CRM system. We have some columns which has input of type 'number'. User can set decimal separator and thousand separator in system settings as per his wish so that all numbers in the grid must be displayed and edited in that format. Say that user has set thousand separator as "." (dot) and decimal separator as "," (comma). I am able to display number in user's format but when it comes to editing the numbers I am not able to do so. As soon as I try to edit number which is displayed in user's format (like 1.234,56) it is getting converted to default format (1234.56).

  1. Is there anyway that I could retain the number in user's format while editing as well?
  2. What happens after I edit number in the user's format? Can DataTable interpret/parse the number by itself based on thousand and decimal separator that we have used?

Please find the below sample code which highlights the issue.

live.datatables.net/sugiyehe/1/edit

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    Is there anyway that I could retain the number in user's format while editing as well?

    You'd need to set it to be "text" rather than a number input. 456,00 is exactly the same as 456. The decimal places of 00 have no meaning. If it was 01 then they would.

    The other option is to use the Masked input plug-in which could be configured as you need.

    Allan

  • debduttacdebduttac Posts: 9Questions: 2Answers: 0

    Hi Allan,

    Thanks for the update.

    That's what we thought of doing (changing the input type to text). But I was under assumption that as we are providing decimal and thousand separators, Datatables should somehow parse the number based on separators (and I was wrong :( ).

    Thanks again
    Deb

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin

    Unfortunately not. I did actually have an idea about this when replying above which I've noted down as a future enhancement (automatic detection of the browser's locale settings), but at the moment the thousands and decimal separator options are for DataTables only and not Editor which just uses HTML5 inputs.

    Allan

This discussion has been closed.