IQueryable / checkbox filtering / client templates

2 posts, 0 answers
  1. Marc
    Marc avatar
    123 posts
    Member since:
    Jul 2010

    Posted 03 Apr Link to this post

    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>
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2306 posts

    Posted 05 Apr Link to this post

    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.
Back to Top