Comma decimal in editor

Comma decimal in editor

GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0
edited November 2014 in Priority support

I am getting the comma decimal rendered correctly in the table by using the following:

           { mData: "LineAmount", sTitle: "LineAmount", "mRender": function (data, type, full) { return formatNumbers(data); } },

which uses the following formatting function:

    function formatNumbers(data) {
        if (data == null) return '';
        var rounded = data.toFixed(2);
        var str = rounded.toString();
        var num = str.replace(".", ",");
        return num;
    }

Everything else is the same is my last post. To save hassle, here is the language spec:

        var oLanguage= {
        "decimal": ",",
        "thousands": ".",
        "sInfo": "@ResHelper.Loc("ShowingPageOfPage")",
        "sSearch": "@ResHelper.Loc("Search")",
        "sZeroRecords": "@ResHelper.Loc("ZeroRecords")",
        "sLengthMenu": "@ResHelper.Loc("LengthMenu")",
        "sInfoEmpty": "@ResHelper.Loc("InfoEmpty")",
        "sInfoFiltered": "@ResHelper.Loc("InfoFiltered")",
        "oPaginate": {
            "sNext": "@ResHelper.Loc("Next")",
            "sPrevious": "@ResHelper.Loc("Previous")"
        }

THE PROBLEM:
When the in-line editor for the field is opened, the numbers look like this: 12.34.

What do I have to do in order to make the in-line editor show a comma in the decimal spot?

This question has an accepted answers - jump to answer

Answers

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

    This is a continuation of your previous thread I presume.

    As I noted there, that problem you are having is that the underlaying data is in a format you don't want. The best solution would be to address the issue there. Failing that, what you need to do is alter the data format once the data has loaded on the client-side, which you can do with the ajax.dataSrc option, using it as a function.

    So you might do:

    ajax: {
      url: ...
      dataSrc: function ( json ) {
        for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
          json.data[i].LineAmount = formatNumbers( json.data[i].LineAmount );
      }
    
      return json.data;
    }
    

    Then remove your mRender function from the column definition, since the data is already in the format you need.

    Now when you edit the field (regardless of whether it is inline, bubble or primary editing) it will show with a comma as the decimal place.

    Keep in mind that using this method, the data submitted to the server will also use a comma as a decimal place! If you try to write that to a database it will likely throw an error. You will need to deformat it, either using preSubmit or on the server-side.

    Regards,
    Allan

This discussion has been closed.