javascript - jsGrid编辑支付金额

标签 javascript jquery plugins grid currency

我正在使用 jsGrid JQuery 插件来显示和编辑付款。虽然这是一个很好的选择,但我无法使用内置字段来编辑“付款金额”。如果我使用“数字”类型,我无法在小数点后输入数字。如果我使用“文本”类型,我可以输入非数字值。

到目前为止,这是我的代码

    $("#jsGrid").jsGrid({
        width: "100%",
        height: "auto",

        editing: true,
        paging: true,
        autoload: true,

        loadIndication: true,
        loadIndicationDelay: 500,
        loadMessage: "Please, wait...",
        loadShading: true,

        controller: {
            loadData: function () {
                return $.ajax({
                    type: "GET",
                    url: AJAX_URL_GET_CALCULATED_AFFECTED_PAYMENTS,
                    data: { 'startDate': startDate, 'endDate': endDate },
                    dataType: "json",
                    cache: false,
                });
            },
        },
        fields: [
            { name: "PaymentDate", title: "Payment Date", type: "text", width: 150, editing: false, },
            { name: "PaymentEndDate", title: "Payment End Date", type: "text", width: 150, editing: false, },
            { name: "PaymentStatusDisplay", title: "Payment Status", type: "text", width: 150, align: "center", editing: false, },
            {
                name: "PaymentAmount", title: "Payment Amount", type: "number", width: 100, align: "center", editing: true,
                itemTemplate: function(value) {
                    return "$" + value;
                },
            },
            { type: "control", deleteButton: false, editButton: true, editButtonTooltip: "Edit Amount", }
        ]
    });

有没有人使用这个插件得到一个例子或设法创建自定义字段类型或使用字段模板编辑 jsGrid 中的字段以仅允许货币值(数字、逗号、小数)

提前谢谢你。

最佳答案

您可以像下面这样定义您的自定义字段:

function MoneyField(config) {
    jsGrid.NumberField.call(this, config);
}

MoneyField.prototype = new jsGrid.NumberField({

    itemTemplate: function(value) {
        return "$" + value.toFixed(2);
    }

    filterValue: function() {
        return parseFloat(this.filterControl.val() || 0);
    },

    insertValue: function() {
        return parseFloat(this.insertControl.val() || 0);
    },

    editValue: function() {
        return parseFloat(this.editControl.val() || 0);
    }

});

jsGrid.fields.money = MoneyField;

现在您可以在指定type="money"的字段中使用它

关于javascript - jsGrid编辑支付金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31935286/

相关文章:

Python插件系统

javascript - 使用 web3 将奇怪的 wei 转换为以太币

javascript - 获取整数框宽度而不是小数值 : Math. ceil() 不向上舍入

jquery - jQuery 中的 ^= 选择器有什么作用?

javascript - 如何在html中创建一个空数组

java - Bukkit 插件多个权限不起作用

java - Maven - Unresolved 对 [javax.activation, javax.annotation] 的引用

javascript - 在 Javascript 中缓存内存中的对象

javascript - 在 ReactJS 中显示来自 flask send_file 函数的图像

javascript - jQuery 从生成的内容生成内容