<label>Render DataSource</label>
@(Html.EJ().DropDownList("dropdown").Datasource((IEnumerable<object>)ViewBag.data).DropDownListFields(df => df.Text("text").Value("value")).Width("100").ClientSideEvents(eve => eve.Change("change")))
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging(true).PageSettings(page => page.PageSize(40))
.Columns(col =>{
col.Type("checkbox").Width(50).Add();
. . .
}))
<script type="text/javascript">
function change(args) {
var query = new ej.Query().addParams("ID", args.text)
var dataManager = ej.DataManager({ url: '@Url.Action("UrlDataSource", "Grid")', adaptor: new ej.UrlAdaptor() });
var promise = dataManager.executeQuery(query);
promise.done(function (e) {
var gridObj = $("#FlatGrid").ejGrid("instance");
var newcols = [], j = 0;
var keys = [], cols = gridObj.model.columns;
for (var key in e.result[0]) {
keys.push(key);
}
for (var i = 0; i < keys.length; i++) {
for (var j = 0; j < cols.length; j++) {
if (keys[i] !== cols[j].field) {
newcols.push({ "field": keys[i] })
}
}
}
gridObj.columns(newcols, "add")
gridObj.dataSource(e.result);
});
}
</script> |
<label>Show/Hide column</label>
@(Html.EJ().DropDownList("dropdown1").Datasource((IEnumerable<object>)ViewBag.data1).DropDownListFields(df => df.Text("text").Value("value")).Width("100").ClientSideEvents(eve => eve.Change("change1")))
@(Html.EJ().Grid<object>("FlatGrid")
.AllowPaging(true).PageSettings(page => page.PageSize(40))
.Columns(col =>
{
col.Type("checkbox").Width(50).Add();
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
. . .
}))
<script type="text/javascript">
function change1(args) {
var gridObj = $("#FlatGrid").ejGrid("instance")
if (args.text == "hide")
gridObj.hideColumns(0)
else if (args.text == "show")
gridObj.showColumns(0)
}
</script> |