|
@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").ValidationRules(new { required = true }).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
. . . . .
col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add();
col.Field("ShipName").HeaderText("Custom Cell").Width("150").AllowEditing(false).Add();
}).AllowPaging().Load("load").PageSettings(page => page.PageSize(10)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true).Mode(Syncfusion.EJ2.Grids.EditMode.Normal); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render()
</div>
<script>
function load() {
city = ["Denmark", "Brazil", "Germany"]
this.columns[4].edit = {
create: function () {
elem = document.createElement('input');
return elem;
},
read: function () {
cellValue = comboBoxObj.value;
return cellValue;
},
destroy: function () {
comboBoxObj.destroy();
},
write: function (args) {
comboBoxObj = new ej.dropdowns.ComboBox({ // create comboBox
dataSource: city,
});
comboBoxObj.appendTo(elem);
}
}
this.columns[5].edit = { // assign ShipCountry value to ShipName field
read: function () {
return cellValue
}
}
}
</script> |
|
|
|
@(Html.EJ().Grid<object>("FlatGrid")
.Columns(col =>
{
col.Field("ShipCity").HeaderText("Ship City").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).Width(110).Add();
}))
</div>
<script>
function create() {
return "<input type='text'/>";
}
function write(args) {
var obj = $('#FlatGrid').ejGrid('instance');
var data = ej.DataManager(obj.model.dataSource).executeLocal(new ej.Query().select("ShipCity"))
args.element.ejComboBox({
dataSource: data,
fields: { text: "ShipCity", value: "ShipCity" },
value: args.rowdata["ShipCity"]
});
}
function read(args) {
return args(".e-combobox").ejComboBox("model.value");
}
</script>
|
|
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging()
.Datasource((IEnumerable<object>)ViewBag.datasource)
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.Columns(col =>
{
col.Field("ShipCity").HeaderText("Ship City").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).Width(110).Add();
}))
</div>
<script>
function create() {
return "<input type='text'/>";
}
function write(args) {
var datasource = @Html.Raw(Json.Encode(ViewBag.datasource));
var data = ej.DataManager(datasource).executeLocal(new ej.Query().select("ShipCity"))
args.element.ejComboBox({
dataSource: data,
fields: { text: "ShipCity", value: "ShipCity" },
value: args.rowdata["ShipCity"]
});
}
function read(args) {
return args.ejComboBox("model.value");
}
</script>
|
|
@(Html.EJ().Grid<object>("FlatGrid")
…………………
.Columns(col =>
{
col.Field("ShipCity").HeaderText("Ship City").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).Width(110).Add();
}))
</div>
<script>
function create() {
…………………….
}
function write(args) {
………………..
}
function read(args) {
setComboValue(args);
return args.ejComboBox("model.value");
}
</script>
<script type="text/javascript">
function setComboValue(args) {
var value = args.ejComboBox("model.value");
var rowIndex = args.closest("tr").index();
var Field = "CustomerID"; //desire field name
gridObj.setCellValue(rowIndex, Field, value);
}
</script>
|