This question is locked. New answers and comments are not allowed.
Hello!
I'm using a Grid with a Custom Server Binding, largely how you do in the examples, just with a little bit more code to provide server-side defaults for filtering, sorting and grouping, and pushing those through a ViewModel to the client and applying them to the Grid, so the UI is in sync with the data displayed.
The problem is, you can't tell from the GridCommand if any of the Descriptors are not set or if the client simple removed any sorting from the grid, since in both cases the properties are populated with an empty List<T>, so there is no way of telling if the empty list of Descriptors or the Defaults apply. See example below.
My approach to change this would be to extend the GridActionAttribute and change the way the GridCommand is built (null / empty Lists respective to if empty descriptors have been supplied or none at all), which seems a little bit like overkill.
Any simpler suggestions than this?
Controller:
ViewModel:
I'm using a Grid with a Custom Server Binding, largely how you do in the examples, just with a little bit more code to provide server-side defaults for filtering, sorting and grouping, and pushing those through a ViewModel to the client and applying them to the Grid, so the UI is in sync with the data displayed.
The problem is, you can't tell from the GridCommand if any of the Descriptors are not set or if the client simple removed any sorting from the grid, since in both cases the properties are populated with an empty List<T>, so there is no way of telling if the empty list of Descriptors or the Defaults apply. See example below.
My approach to change this would be to extend the GridActionAttribute and change the way the GridCommand is built (null / empty Lists respective to if empty descriptors have been supplied or none at all), which seems a little bit like overkill.
Any simpler suggestions than this?
Controller:
[GridAction(GridName = "user-grid")] public ActionResult Index(GridCommand command) { var vm = new UserGridViewModel().ApplyGridCommand(command); (yadda, yadda, yadda...) return View(vm); }
ViewModel:
public class GridViewModel { (yadda, yadda...) public GridViewModel ApplyGridCommand(GridCommand command) { Page = !command.IsEmpty() && command.Page > 0 ? command.Page : Page; PageSize = !command.IsEmpty() ? command.PageSize : PageSize; // No way of telling if Descriptors have been removed (orderBy=~) or if there are none set and Defaults should be applied, // since command.SortDescriptors is always an empty list in both cases. SortDescriptors = !command.IsEmpty() && command.SortDescriptors.Any() ? command.SortDescriptors : SortDescriptors; return this; } } public class UserGridViewModel : GridViewModel { public UserGridViewModel() { SortDescriptors.Add(new SortDescriptor { Member = "Name" }); } } // Other *GridViewModel with different defaults