@Html.EJS().Grid("FlatGrid").DataSource((IEnumerable<object>)ViewBag.griddata).AllowFiltering(true).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Columns(col =>
{
col.Field("BUKey").HeaderText("Key").Width("100").IsPrimaryKey(true).IsIdentity(true).AllowEditing(false).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add();
col.Field("BUAbbr").HeaderText("BU Abbr").Width("100").AllowEditing(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add();
col.Field("BUName").HeaderText("BU Name").Width("200").AllowEditing(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).Add();
col.Field("PrntBUKey").HeaderText("PrntBUKey").Width("100").Visible(true).AllowEditing(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Left).DefaultValue("0").Add();
col.Field("PrntBUName").HeaderText("PrntBUName").EditType("dropdownedit").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("150").Add();
col.Field("IsAct").HeaderText("IsAct").EditType("booleanedit").DisplayAsCheckBox(true).Type("boolean").Width("150").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
}).AllowPaging().EditSettings(edit => { edit.AllowEditing(true).AllowAdding(true).Mode(Syncfusion.EJ2.Grids.EditMode.Batch).ShowConfirmDialog(false); }).Render()
<script>
var elem;
var dObj;
function create(args) {
elem = document.createElement('input');
return elem;
}
function write(args) {
var datasource = @Html.Raw(Json.Encode(ViewBag.PrntBUDataSource));
dObj = new ej.dropdowns.DropDownList({
dataSource: new ej.data.DataManager(datasource),
fields: { text: 'PrntBUName', value: 'PrntBUName' },
popupHeight: '230px',
value: args.rowData[args.column.field],
change: dropChange
});
dObj.appendTo(elem);
}
function destroy() {
dObj.destroy();
}
function read(args) {
return dObj.text;
}
function dropChange(args) {
var gridObj = document.getElementsByClassName("e-grid")[0].ej2_instances[0];
var value = args.value;
var rowIndex = gridObj.selectedRowIndex;
var Field = "PrntBUKey"; //desire field name
gridObj.updateCell(rowIndex, Field, value);
}
</script>
|