【问题标题】:Free-jgrid and input mask: Format number while type in inline edit modeFree-jgrid 和输入掩码:在内联编辑模式下输入时格式化数字
【发布时间】:2018-08-10 03:24:12
【问题描述】:

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

【问题讨论】:

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


    【解决方案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/

    【讨论】:

    • 我认为 rowidiRow 是一样的,但它只适用于 jqgrid 而不是 free-jqgrid。谢谢奥列格。
    猜你喜欢
    • 2011-09-24
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多