2011-07-21 31 views
5

在我的格式,我有以下代码:jqGrid的数字格式化使用

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

,在我colModel我:

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

我的数据类型设置为 “本地”

当我第一次显示表单时,我得到了“0.00”而不是“0.0000”,正如我所希望的那样。此外,在内联编辑模式下,SalesPrice值根据网格中的其他单元格而变化。更新后,SalesPrice值显示为整数。

我会做什么错?

编辑:更完整的代码

$("#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' 
}); 

回答

6

你不公布完整的代码,所以现在还很难说你有什么问题。只要看看the demo,你可以解释并且没有问题。

我使用了formatoptions,因为我不清楚你在哪里设置了numberformatter值。

+0

我按照这里的例子http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter。基本上,我是为整个网格而不是特定的列声明格式化程序。使用给定的例子在网格的初始加载中工作。但是,当SalesPrice的值发生变化时,我仍然得到一个返回的整数。我将更新OP – DavidS

+0

中的代码SalesPrice更新的问题与格式没有任何关系,尽管有些人可能预期将值“3”传递为“格式化”为“3.000”。但我找到了解决这个问题的办法。所以,格式化程序的唯一未解决的问题与全局声明格式化程序似乎不像预期一样。也许我错了。 – DavidS

+1

@DavidS:您误解了http://www.trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter中的信息。例如grid.locale-en.js的特定于语言的文件定义了具有许多属性(包括“$ .jgrid.formatter.number”)的$ .jgrid对象。例如,你可以设置'$ .jgrid.formatter.number.decimalPlaces = 4; $ .jgrid.formatter.number.defaultValue:'0.0000';'在调用'$(“#customerOrderLineList”)。jqGrid({...});'之前'。您可以覆盖设置,但没有jqGrid的'formatter'参数。 – Oleg