jqgrid格式化程序实际上应该做什么



我正在尝试使用可编辑的jqgrid网格实现格式化程序。 我已经阅读了有关它的维基页面,但它并没有真正提到它应该做什么。 它只是说它格式化。

例如,这是我的一段代码(这是来自列定义部分):

{ name: 'daily', index: 'daily', width: 90, sorttype: "currency", editable: true, formatter: 'currency', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2, prefix: "$ " } },

我对格式化程序应该做什么的期望:由于这是一种货币,因此不允许用户输入字母,符号等(仅数字)在数字前面放置一个美元符号将小数点放在正确的位置将千逗号放在正确的位置。

它没有做这些。 那么我应该对格式化程序有什么期望呢?

jqGrid 格式化程序只是一个格式化单元格数据的函数:

function myformatter ( cellvalue, options, rowObject )
{
    // format the cellvalue to new format
    return new_formated_cellvalue;
}

如您所见,它只允许格式化要显示的单元格内容,不执行任何验证。

<小时 />

如果要验证编辑后的数据是否以特定格式输入,则需要将editrules添加到 colModel。例如,您可以使用以下选项之一:

number    boolean  (true or false) if set to true, the value will be
                   checked and if this is not a number, an error message 
                   will be displayed.
custom    boolean  if set to true allow definition of the custom checking 
                   rules via a custom function. See below

最新更新