jqgrid数字格式化程序的使用
在我的格式化程序中,我有以下代码:jqgrid数字格式化程序的使用,jqgrid,jqgrid-formatter,Jqgrid,Jqgrid Formatter,在我的格式化程序中,我有以下代码: formatter: { number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' } }, 在我的模型中,我有: { name: 'SalesPrice', index: 'SalesPrice', width: 90, align: 'left', formatter:'number', editable
formatter: {
number: { decimalSeparator: ".", thousandsSeparator: " ", decimalPlaces: 4, defaultValue: '0.0000' }
},
在我的模型中,我有:
{ 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'
});
您没有发布完整的代码,因此很难说您的问题是什么。只要看看你解释的是什么,没有问题
我使用了
formatoptions
,因为我不清楚您在哪里为thnumber
设置了格式化程序的值。基本上,我是为整个网格而不是特定列声明格式化程序。利用给出的例子,对电网的初始负荷进行了计算。然而,当SalesPrice的值改变时,我仍然得到一个整数返回。我将更新OPP中的代码。SalesPrice更新的问题与格式无关,尽管有些人可能会期望传递为“3”的值被“格式化”为“3.000”。但我找到了解决这个问题的办法。因此,我对格式化程序唯一一个悬而未决的问题是,在全局范围内声明格式化程序似乎并不像预期的那样有效。也许我错了。@DavidS:你误解了我们的信息。特定于语言的文件,例如grid.locale-en.js定义了$.jgrid
对象,该对象具有许多属性,包括$.jgrid.formatter.number
。例如,您可以设置$.jgrid.formatter.number.decimalPlaces=4;$。jgrid.formatter.number.defaultValue:'0.0000'调用$(“#customerOrderLineList”).jqGrid({…})之前的代码>代码>。您可以覆盖设置,但jqGrid没有格式化程序
参数。是的,这似乎是我误解了,这就是它不起作用的原因。