<ejs-grid id="DefaultGrid" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editSettings>
<e-grid-columns>
. . . . . .
<e-grid-column field="ShipCity" headerText="ShipCity" width="120" edit="@(new {create="fileCreate", read="fileRead", destroy="fileDestroy", write="fileWrite" })"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script type="text/javascript">
var elem;
var elementObj;
var checked;
function fileCreate() {
elem = document.createElement('input');
return elem;
}
function fileRead(args) {
debugger;
if (elementObj.element.classList.contains('e-checkbox')) {
return elementObj.checked;
}
else {
return elementObj.value;
}
}
function fileDestroy() {
elementObj.destroy();
}
function fileWrite(args) {
if (args.rowData.ShipCity === "false" || args.rowData.ShipCity === "true") {
if (args.rowData.ShipCity === "false") checked = false; if (args.rowData.ShipCity === "true") checked = true;
elementObj = new ej.buttons.CheckBox({
checked: checked
});
elementObj.appendTo(elem);
}
else {
elementObj = new ej.inputs.TextBox({
value: args.rowData.ShipCity
});
elementObj.appendTo(elem);
}
}
</script> |
<script type="text/javascript">
var elem;
var elementObj;
var checked;
var gridObj;
function fileCreate() {
elem = document.createElement('input');
return elem;
}
document.addEventListener('DOMContentLoaded', function () {
gridObj = document.getElementsByClassName('e-grid')[0].ej2_instances[0];
});
function save(args) {
gridObj.columns[2].validationRules = "";
}
function fileRead(args) {
debugger;
if (elementObj.element.classList.contains('e-checkbox')) {
return elementObj.checked;
}
else {
return elementObj.value;
}
}
function fileDestroy() {
elementObj.destroy();
}
function fileWrite(args) {
if (args.rowData.ShipCity === "false" || args.rowData.ShipCity === "true") {
if (args.rowData.ShipCity === "false") checked = false; if (args.rowData.ShipCity === "true") checked = true;
elementObj = new ej.buttons.CheckBox({
checked: checked
});
elementObj.appendTo(elem);
}
else {
elementObj = new ej.inputs.TextBox({
value: args.rowData.ShipCity
});
elementObj.appendTo(elem);
gridObj.columns[2].validationRules = { required: true }; // required column
}
}
</script> |
var customFn = function(args) {
return args['value'].length >= 5;
};
var grid = new ej.grids.Grid({
dataSource: data,
toolbar: ['Add', 'Edit', 'Delete', 'Update', 'Cancel'],
editSettings: { allowEditing: true, allowAdding: true, allowDeleting: true, mode: 'Normal' },
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 100, isPrimaryKey: true, validationRules: { required: true } },
{ field: 'CustomerID', headerText: 'Customer ID', width: 120, validationRules: { required: true, minLength: [customFn, 'Need atleast 5 letters'] } },
{ field: 'Freight', headerText: 'Freight', textAlign: 'Right', editType: 'numericedit', width: 120, format: 'C2' },
{ field: 'ShipCountry', headerText: 'Ship Country', editType: 'dropdownedit', width: 150 }
],
height: 273
});
customFn
=
function(args)
{
return args
['value'].length
>=
5;
customFn
=
function(args)
{
return args
['value'].length
>=
5;
<ejs-grid id="myGrid" ...>
<e-grid-editsettings mode="Batch" allowAdding="false" cellEdit ="cellEdit" allowDeleting="false" allowEditing="true"
showConfirmDialog="true" />
<e-data-manager adaptor="UrlAdaptor" url="@Url.Action("GetCfgData", "Config")"
batchUrl="@Url.Action("ExecCfgBatch", "Config")" />
...
<e-grid-columns>
<e-grid-column field="Id" visible="false" allowEditing="false" isPrimaryKey="true" />
<e-grid-column field="Name" allowEditing="false" />
<e-grid-column field="FieldType" visible="false" allowEditing="false" />
<e-grid-column field="FieldValue" />
<e-grid-column field="Range" textAlign="Right" allowEditing="false" />
</e-grid-columns>
</ejs-grid>
<script>
var customFn1 = function(args) {
// you can perform your own regx here
};
var customFn2 = function(args) {
};
var customFn3 = function(args) {
// you can perform your own regx here };
function cellEdit(e) {
if (e.columnName == 'FieldValue') {
// check the column value is number set range validation
if (!isNaN(parseInt(e.rowData['FieldValue']))) {
this.getColumnByField('FieldValue').validationRules = { required: true, minLength: [customFn1, 'enter the value 1 to 10'] }
}
// check the column value as Boolean , no validation
if (e.rowData['customerID'] == 'true' || e.rowData['customerID'] == 'false') {
this.getColumnByField('FieldValue').validationRules = {}
}
// check the column value is string set range minLength validation
else {
this.getColumnByField('FieldValue').validationRules = { required: true, minLength: [customFn2, 'Need atleast 3 letters'] }
}
}
}
</script> |