<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Normal"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID" width="120" edit="@(new {create="create", read="read", destroy="destroy", write="write"})"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
var ddlObject;
var data = @Json.Serialize(ViewBag.DataSource);
function create() {
// create a input element
return document.createElement('input');
}
function read(args) {
// return the value which will be saved in the grid
return ddlObject.value;
}
function destroy() {
// destroy the custom component.
ddlObject.destroy();
}
function write(args) {
console.log(args);
console.log(args.rowData);
// create a autoComplete control
ddlObject = new ej.dropdowns.AutoComplete({
//bind the data manager instance to dataSource property
dataSource: data,
//bind the current cell value to the Dropdown which will be displayed only when the dropdown dataSource contains that value
value: args.rowData[args.column.field],
//map the appropriate columns to fields property
fields: { text: 'CustomerID', value: 'CustomerID' },
//set the placeholder to DropDownList input
placeholder: "Find a customer"
});
//render the component
ddlObject.appendTo(args.element);
}
</script>
|
<script>
----
function write(args) {
ddlObject = new ej.dropdowns.AutoComplete({
dataSource: data,
showPopupButton: true, // renders the popup button
value: args.rowData[args.column.field],
fields: { text: 'CustomerID', value: 'CustomerID' },
});
ddlObject.appendTo(args.element);
}
</script>
|
<script>
----
function write(args) {
console.log(args);
console.log(args.rowData);
ddlObject = new ej.dropdowns.ComboBox({
dataSource: data,
value: args.rowData[args.column.field],
fields: { text: 'CustomerID', value: 'CustomerID' },
});
ddlObject.appendTo(args.element);
}
</script>
|