【问题标题】:jqgrid number formatter usejqgrid数字格式化程序使用
【发布时间】:2011-10-10 02:11:45
【问题描述】:

在我的格式化程序中,我有以下代码:

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'
});

【问题讨论】:

    标签: jqgrid jqgrid-formatter


    【解决方案1】:

    您没有发布完整的代码,因此很难说出您的问题所在。看看the demo哪个按你解释的没问题。

    我使用了formatoptions,因为我不清楚您为number 设置formatter 值的位置。

    【讨论】:

    • 我在trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter 处遵循示例。基本上,我是为整个网格而不是特定列声明格式化程序。使用给出的示例对网格的初始负载起作用。但是,当 SalesPrice 的值发生变化时,我仍然会返回一个整数。我将更新 OP 中的代码
    • SalesPrice 更新的问题与格式没有任何关系,尽管有些人可能期望作为“3”传递的值被“格式化”为“3.000”。但我找到了解决这个问题的方法。因此,我对格式化程序的唯一突出问题与全局声明格式化程序似乎无法按预期工作有关。也许我错了。
    • @DavidS:您误解了来自trirand.com/jqgridwiki/doku.php?id=wiki:predefined_formatter 的信息。特定于语言的文件,例如 grid.locale-en.js 定义 $.jgrid 具有许多属性的对象,包括 $.jgrid.formatter.number。例如,您可以在调用$("#customerOrderLineList").jqGrid({...}); 之前设置$.jgrid.formatter.number.decimalPlaces=4; $.jgrid.formatter.number.defaultValue: '0.0000';。可以覆盖设置,但是jqGrid没有formatter参数。
    • 是的,看来我误解了,这就是它不起作用的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多