我正在使用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'
});
答案 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
});
}