我正在使用 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/