I am using jsGrid JQuery plugin to display and edit payments. Although it is an excellent option I am unable to use the build-in fields to edit a 'Payment Amount'. If I use the 'number' type, I am not able to enter digits after the decimal place. If I use the 'text' type I can enter non-numeric values.
Here is my code so far
$("#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", }
]
});
Has anyone used this plugin got an example or managed to create a custom field type or use the field templates to edit a field in jsGrid to only allow currency values (number, comma, decimals)
Thank you in advance.
You can define your custom field like the following:
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;
Now you can use it in field specifing type="money"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With