<input type="button" onclick="changeDatasource()" value="ChangeData"/>
@(Html.EJ().Grid<BasicMVCSample.Grid.OrdersView>("ForeignKey")
. . .
.Columns(col =>
{
. . .
col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2)
.TextAlign(TextAlign.Left).Width(90).Add();
. . .
})
)
@button click event
function changeDatasource(args) {
// here we can change the grid data source dynamically using set model
$("#ForeignKey").ejGrid("option", {
dataSource:@Html.Raw(Json.Encode(@ViewBag.DataSource1)),
columns:[
{ field: "EmployeeID",foreignKeyField: "EmployeeID", foreignKeyValue: "LastName", dataSource:@Html.Raw(Json.Encode(@ViewBag.DataSource2)), headerText: "Last Name", width: 75, textAlign: ej.TextAlign.Right, priority: 4 },
. . .
],
})
}
|
HI,
Regret for the confusion my requirement is as follows.
I have a grid in which one column shows available seats /slots
which can be allocated to different members and will change once the grid
submitted or refreshed.
I have a grid with listbox.
Listbox data should be
populated using Json from the controller
When grid source is
refreshed [after batchsave] , the listbox data should also be refreshed from
server using JSON.
Right now issue is when I
submit and batchsave grid , the data source of listbox remains
old. It should get the data using json from the server again.
Thanks for your quick support.
@(Html.EJ().Grid<object>("ForeignKey")
.Datasource((IEnumerable<object>)ViewBag.dataSource1)
. . .
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
. . .
.Columns(col =>
{
. . .
col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.dataSource2)
.TextAlign(TextAlign.Left).Width(90).Add();
. . .
}).ClientSideEvents(eve =>
{
eve. ActionComplete("actionComplete").CellEdit("cellEdit")
})
)
@cellEdit event
function cellEdit(args) {
setTimeout(function () {
var dpDataSource = [{ value: 1, text: 'One' }, { value: 2, text: 'two' }, { value: 3, text: 'three' }, { value: 4, text: "four" }, { value: 5, text: "five" }, { value: 6, text: "six" }, { value: 7, text: "seven" }, { value: 8, text: "eight" }, { value: 9, text: "nine" }, ];
$("#ForeignKeyEmployeeID").ejDropDownList({ dataSource: dpDataSource, selectedIndex: 1 }); //Set the new Dropdown datasource
}, 2)
} |