I have posted the question before and I thought that I managed to fix the issue but it turns out that I made a mistake. I contacted the support but we still haven't figured out how to fix the problem. I also think that it is pretty hard to understand the issue so I am posting it here and I hope that someone will be able to help.
Basically I have 2 grids on one screen. One shows the Positions in a company, the other shows the staff and their positions. So far so good. The staff grid has a foreign key to the positions table because you know these positions change and they can be updated, so our staff model only holds an id of the specific position. Both Grids are on the same screen and are ajax bound. I have a mechanism that refreshes both grids if there is a change. (dataSource.read() does the trick). I have attached scheme.
I do not want to refresh the screen. I saw from a demo in the docs that when I have a foreign key to some table the Grid uses ViewData to pass the values and map them to their specific Ids. A problem occurs when I edit the Position name in the first grid (the positions grid) and try to refresh the second one (the staff grid). As the staff grid holds only the id of the postion and as we cannot update the ViewData without refreshing the screen, the value remains the same even after I refresh the staff grid. I can edit the staff and change their positions but if I edit the grid from the positions grid, the changes are not visible in the staff gird without refreshing.
I have popup edit mode enabled with custom editor for the staff gird and there is a drop down for the foreign key column (postion name) which is beign updated when I refresh the grid and thats fine (it is bound to ajax so we don't have problem here). We need the foreign key columns Ajax bound, not ViewData bound. Of course I could edit my model and add a extra field to hold my Position title and pass it to the screen and use it instead of foreign key but that's not the idea.
- I don't want to refresh the page.
- I have attached a scheme.
Here is some source code that I use:
View (only the staff grid, that's what's important):
columns.Bound(p => p.Name);
columns.ForeignKey(p => p.PositionId, (System.Collections.IEnumerable)ViewData["positions"], "Id", "PositionName");
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.DataSource(dataSource => dataSource
.Read(read => read.Action("Staff_Read", "Staff"))
.Update(update => update.Action("Staff_Update", "Staff"))
.Create(create => create.Action("Staff_Create", "Staff"))
Controller(the index method that fills the ViewData):
public ActionResult Index ()
ViewData["positions"] = context.Positions.Select(position => new
Id = position .Id,
PositionName = position.PositionName
Hope I explained it good enough and someone could help me.