Author Topic: Entering decimal comma  (Read 2602 times)

KR

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 8
    • View Profile
Entering decimal comma
« on: July 21, 2016, 11:45:18 am »
Hello,

Please take a look at http://jsfiddle.net/1k5r9j0v/1/

Formatting is done by using format: '##.###,00' in the colmodel. This works great!

However, when editing the values, it does not allow comma as decimal mark. Is there a way of allowing this? Our users must be able to input an amount like 1234,56.

Do I have to use data type string instead?

Thank you.
KR.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Entering decimal comma
« Reply #1 on: July 21, 2016, 06:14:24 pm »
Thanks for sharing jsfiddle.

That would require disabling the filterKeys feature in column.editModel and customizing the editor to replace "." by "," during initialization and replace "," by "." during saving data from editor.

Code: [Select]
                editModel: { filterKeys: false },
                editor: {
                   init: function(ui){
                  var $inp = ui.$cell.find("input"),
                    val = $inp.val();
                    //replace "." by "," 
                    val = val.replace(".",",");
                    $inp.val(val);
                  },
                  getData: function(ui){                   
                    var val = ui.$cell.find("input").val();
                    //replace "," by "." 
                    val = val.replace(",",".");                   
                    return parseFloat(val);
                  }
               }               

http://jsfiddle.net/1k5r9j0v/2/

KR

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Entering decimal comma
« Reply #2 on: July 22, 2016, 11:37:06 am »
Thank you!