This is a migrated thread and some comments may be shown as answers.

IQueryable / checkbox filtering / client templates

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 03 Apr 2018, 03:10 PM

We have a very large datastore connected to a kendo grid, so it's important that the DataSourceRequest object is translated to the sql for server paging, filtering, etc.

One issue is that the datastore stores employee ids and we want to display their names and have a checkbox filter datasource that shows all unique names (not just the names from the paged views).

I have this all working but I'm currently hijacking the DataSourceRequest and manually parsing through and converting the FIlterDescriptor objects from the display names to the ids in the database.

I've done plenty of wrangling trying to get this all to work with client templates to no avail.

Here's a code snippet that represents what I'm doing. Is there a better approach?

 

 

<p>public JsonResult GetAssets([DataSourceRequest] DataSourceRequest request)
{
    var assetQuery = _assetRepository.GetAllKendoReadOnly();
    request = ToAssetDataSourceRequest(request); //converts filters from name to id
    var assets = assetQuery.ToDataSourceResult(request, ToAssetViewModel); //ToAssetViewModel populates names from ids
    return Json(assets, JsonRequestBehavior.AllowGet);
}
  private DataSourceRequest ToAssetDataSourceRequest(DataSourceRequest request)
{
    if (request.Filters != null && request.Filters.Any())
    {
        foreach (var iFilter in request.Filters)
        {
            ConvertFilter(iFilter);
        }
    }
  
    return request;
}
  private void ConvertFilter(IFilterDescriptor descriptor)
{
    switch (descriptor)
    {
        case FilterDescriptor filterDescriptor:
            ToConvertedDescriptor(filterDescriptor);
            break;
        case CompositeFilterDescriptor compositeFilterDescriptor:
            foreach (var compositeFilter in compositeFilterDescriptor.FilterDescriptors)
            {
                ConvertFilter(compositeFilter);
            }
            break;
    }
}
  private void ToConvertedDescriptor(FilterDescriptor filter)
{
    switch (filter.Member)
    {
        case "OnwerName":
            filter.Member = "OwnerEmployeeNumber";
            filter.Value = GetEmployeeNumber(filter.Value.ToString());
            break;
        case "CustodianName":
            filter.Member = "CustodianEmployeeNumber";
            filter.Value = GetEmployeeNumber(filter.Value.ToString());
            break;
        case "UserName":
            filter.Member = "UserEmployeeNumber";
            filter.Value = GetEmployeeNumber(filter.Value.ToString());
            break;
    }
}</p><p></p>

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 05 Apr 2018, 09:08 AM
Hello Marc,

You could take a look at the ForeignKey column and see if it is suitable for your exact scenario:
Note that the column is bound to the Value field and the Grid automatically matches that value with the text field, using the collection passed to the column.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Marc
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or