jqgrid number formatter use

DavidS picture DavidS · Jul 21, 2011 · Viewed 28k times · Source

In my formatter, I've got the following code:

formatter: {
    number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }
},

and in my colModel I have:

  { name: 'SalesPrice', index: 'SalesPrice', width: 90, align: 'left', formatter:'number', editable: true, editoptions:
                  {
                      readonly: true
                  }
                  }

My datatype is set to "local"

When I first display the form, I get "0.00" and not "0.0000" as I was hoping for. Morever, in inline editing mode, the SalesPrice value changes depending upon other cells in the grid. After the updates the SalesPrice value is shown as an integer.

What could I be doing wrong?

EDIT: More complete code

$("#customerOrderLineList").jqGrid({
    //      url: 'someUrl',
    datatype: 'local',
    formatter: {
        number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }
    },
    //      mtype: 'POST',
    colNames: [ 'Part Number', 'Sales Price'],
    colModel: [
                  { name: 'PartNumber', index: 'PartNum', width: 90, align: 'left', editable: true, editoptions:
                  {
                      dataInit: function (el) {
                          $(el).autocomplete({
                              source: "Autocomplete",
                              minLength: 1
                          });
                      }
                  }
                  },

                  { name: 'SalesPrice', index: 'SalesPrice', width: 90, align: 'left', formatter: 'number',
                      formatoptions: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }, editable: true, editoptions:
                  {
                      readonly: true
                  }
                  }
             ],
    pager: jQuery('#pager'),
    rowNum: 10,
    rowList: [5, 10, 20, 50],
    sortable: true,
    sortname: 'PartNum',
    sortorder: "asc",
    viewrecords: true,
    imgpath: '',
    autowidth: true,
    onSelectRow: function (id, status) {
        if (id && id !== lastsel) {
            $('#customerOrderLineList').jqGrid('restoreRow', lastsel);
            $('#customerOrderLineList').jqGrid('editRow', id, true);
            lastsel = id;
        }
    },
    caption: 'Caption'
});

Answer

Oleg picture Oleg · Jul 21, 2011

You don't posted your full code so it's difficult to say what is your problem. Just look at the demo which do what you explain and has no problem.

I used formatoptions because it was unclear for me where you set the formatter values for th number.