I'm using Kendo grid (and other components) through the MVC wrapper. Recently, I started using sorting and filtering, in the following way:
.DataSource(dataSource => dataSource.Ajax()
.Read(read => read.Action(action name, controller name)
1) Sort and Filter MVC calls take the view model fields, which eventually fill the DataSourceRequest. How exactly does that translate through the dynamic linq into sql? Does it rely on the assumption that the name of the field in the view model will be the same as in the data model?
I mean, if I use something like
dataSource.Filter(filter => filter.Add(viewModel => viewModel.MachineId).IsEqualTo(machineId));
and later the request object (with field names as strings) with those filters, sorts etc goes into .ToDataSourceResult(),
how does it know which field in the data model - in the Entity Framework entity, that is - does the viewModel.MachineId map to?
For myself, I use AutoMapper, so through the mapper configuration, I know which field is which... but Kendo MVC side doesn't have that knowledge.
And if it makes an assumption about data model and view model field names being the same, how do I pass it the actual data model field name in cases when they aren't the same?
2) Is there any advantage to using extra parameters in the controller call, to filter the data, versus using Filter(), so that all the filtering info ends up in one and the same object, the DataSourceRequest?
If I add extra parameters to the controller call, I need to implement a separate controller call for each combination of parameters. And, in each call, I have to add all the sql conditions myself. If I can just use Filter() in the grid definition, I can keep reusing the same controller call for all combinations.
And, theoretically, through dynamic linq, when the data request object is passed into .ToDataSourceResult, this should result in all the "where" conditions being correctly applied, and the filtering performed in sql, on the sql server side... or am I wrong here?
Yet, your code samples with master/detail grids (a master grid with a detail template which contains another grid) used a separate controller call with the parameter; is there a reason for it, if it could have been simply filtered by this field?
3) How would I use Filter() in a grid / data source defined in the detail template of another grid?
The problem here is that related operators, such as IsEqualTo(), expect me to know the value on the server side, at the time C# is executed.
However, in a grid detail template, for the detail grid construction, this value is only known on the client side.
A call like .IsEqualTo("#=template_field_here#")) won't work; the argument is obviously a string, yet the .IsEqualTo expects the argument to be of the same type as the field I'm filtering... which makes sense only if I knew it on the server, outside of the detail template.
Would I have to write the whole detail grid in jquery?
(Yes, I could - and I did - write a separate controller call, with extra parameters, to accomplish this; I'm just trying to remove that code, if I really don't have to do it that way... if it can work simply through filters in the DataSourceRequest)