|
Index.js
var grid = new ej.grids.Grid({
dataSource: data,
toolbar: ['Add', 'Edit', 'Delete'],
editSettings: {
allowEditing: true,
allowAdding: true,
allowDeleting: true,
mode: 'Dialog',
template: '#dialogtemplate'
},
columns: [
{
field: 'OrderID',
headerText: 'Order ID',
textAlign: 'Right',
width: 100,
isPrimaryKey: true
},
{ field: 'CustomerID', headerText: 'Customer ID', width: 120 },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150 }
],
height: 265,
actionBegin: function(args) {
if (args.requestType === 'save') {
// cast string to integer value.
args.data['Freight'] = parseFloat(
args.form.querySelector('#Freight').value
);
}
},
actionComplete: function(args) {
if (args.requestType === 'beginEdit' || args.requestType === 'add') {
// Add Validation Rules
args.form.ej2_instances[0].addRules('Freight', { max: 500 });
// EJ2-control Rendering
new ej.dropdowns.DropDownList(
{
value: args.rowData.ShipCountry,
popupHeight: '200px',
floatLabelType: 'Always',
dataSource: countryData,
fields: { text: 'ShipCountry', value: 'ShipCountry' },
placeholder: 'Ship Country'
},
args.form.elements.namedItem('ShipCountry')
);
new ej.buttons.CheckBox(
{ label: 'Verified', checked: args.rowData.Verified },
args.form.elements.namedItem('Verified')
);
new ej.inputs.NumericTextBox(
{
value: args.rowData.Freight,
format: 'C2',
placeholder: 'Freight',
floatLabelType: 'Always'
},
args.form.elements.namedItem('Freight')
);
// Set initail Focus
if (args.requestType === 'beginEdit') {
args.form.elements.namedItem('CustomerID').focus();
}
}
}
});
grid.appendTo('#Grid'); |