自由栅格和输入掩码:在内联编辑模式下键入时,格式化数字

时间:2018-08-10 03:24:12

标签: jqgrid number-formatting free-jqgrid jquery-inputmask

我正在使用free-jqgrid v.4.15.4

我要在嵌入式编辑模式下键入数字来格式化数字。

我正在使用RobinHerbots的产品Inputmask来实现这一目标。

它与jqgrid v.4.6.0兼容,但不适用于free-jqgrid。

那我要怎么解决呢?

这是2个jsfiddle:

Jqgrid v.4.6.0:demo with jqgrid

Free-jqgrid v.4.15.4:demo with free-jqgrid

 var mydata = [{
    name: "Toronto",
    country: "Canada",
    continent: "North America",
    quantity: 1200000
}, {
    name: "New York City",
    country: "USA",
    continent: "North America",
     quantity: 2200000
}, {
    name: "Silicon Valley",
    country: "USA",
    continent: "North America",
     quantity: 3200000
}, {
    name: "Paris",
    country: "France",
    continent: "Europe",
     quantity: 4200000
}]

$("#grid").jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ["Name", "Country", "Continent","Quantity"],
    colModel: [{
        name: 'name',
        index: 'name',
        editable: true,
    }, {
        name: 'country',
        index: 'country',
        editable: true,
    }, {
        name: 'continent',
        index: 'continent',
        editable: true,
    },{
        name: 'quantity',
        index: 'quantity',
        editable: true,
             formatter:'number',
                        formatoptions:{decimalSeparator:".", thousandsSeparator: " ", decimalPlaces: 2}
    }],
    pager: '#pager',
    'cellEdit': true,
   afterEditCell: function (rowid, cellname, value, iRow, iCol) {
                $('#' + rowid + '_quantity').inputmask("decimal", {
                        radixPoint: '.',
                        groupSeparator: ',',
                        digits: 2,
                        autoGroup: true,
                        rightAlign: false,
                        clearMaskOnLostFocus: false
                    });
    },
    'cellsubmit' : 'clientArray',


    editurl: 'clientArray'
});

1 个答案:

答案 0 :(得分:1)

原因很简单:您使用rowid而不是iRow。固定代码为

afterEditCell: function (rowid, cellname, value, iRow, iCol) {
   $('#' + iRow + '_' + cellname).inputmask("decimal", {
       radixPoint: '.',
       groupSeparator: ',',
       digits: 2,
       autoGroup: true,
       rightAlign: false,
       clearMaskOnLostFocus: false
   });
}

请参见http://jsfiddle.net/OlegKi/6yc28po5/14/