7

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'
});
DavidS
  • 2,179
  • 4
  • 26
  • 44

1 Answers1

7

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.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I was following the example here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter. Basically, I was declaring the formatter for the whole grid rather than for a particular column. Using the example given works on initial load of grid. However, when the value of SalesPrice changes I still get an integer returned. I'll update the code in the OP – DavidS Jul 21 '11 at 12:23
  • The issue with the SalesPrice update didn't have anything to do with the formatting, although some might have expected the value being passed as "3" to be "formatted" as "3.000". But I've found a solution to this problem. So really the only outstanding issue I have with the formatter is related to the fact that declaring the formatter globally doesn't seem to work as expected. Maybe I'm wrong. – DavidS Jul 21 '11 at 12:56
  • 1
    @DavidS: You misunderstand the information from http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter. The language specific file for example grid.locale-en.js define `$.jgrid` object having many properties inclusive `$.jgrid.formatter.number`. For example you can set `$.jgrid.formatter.number.decimalPlaces=4; $.jgrid.formatter.number.defaultValue: '0.0000';` before call of `$("#customerOrderLineList").jqGrid({...});`. You can overwrite the settings, but there are no `formatter` parameter of jqGrid. – Oleg Jul 21 '11 at 13:35
  • yes it would appear that I misunderstood and that's why it wasn't working. – DavidS Jul 21 '11 at 13:48