Filtering grid with data from resource file

2 posts, 1 answers
  1. Vangel
    Vangel avatar
    6 posts
    Member since:
    Jun 2011

    Posted 21 Mar Link to this post

    I have table in database which contains events of a system and these events have severity code and event code. These codes have to be localized, it means the text for the severity and event codes should be taken from resource files.

    Here is how we construct data for the grid:

    public ActionResult GetEvents([DataSourceRequest] DataSourceRequest request)
        IQueryable<SystemEventGridModel> data = SystemEvent.GetSystemEventFromDatabase().Select(systemEvent =>
            new SystemEventGridModel
                Id = systemEvent.Id,
                EventCode = systemEvent.EventCode,
                SeverityCode = systemEvent.SeverityCode,
                Date = systemEvent.Date,
                Node = systemEvent.Node,
                IsActive = systemEvent.IsActive
        DataSourceResult dataSourceResult = data.ToDataSourceResult(request);
        foreach (SystemEventGridModel gridModel in dataSourceResult.Data)
            gridModel.EventText = Language.ResourceManager.GetString($"EventText{gridModel.EventCode}");
            gridModel.SeverityText = Language.ResourceManager.GetString($"SeverityText{gridModel.SeverityCode}");
        return Json(dataSourceResult);


    Then in the grid we show the localized text but not the codes:

          .Columns(columns =>
              columns.Bound(x => x.Node).Title(Language.SystemEventGridModelTitleNode);
              columns.Bound(x => x.SeverityCode).Title(Language.SystemEventGridModelTitleSeverityText).ClientTemplate("#=SeverityText#").Filterable(x => x.Multi(true).CheckAll(false).ItemTemplate("function(e){return columnFirtalableItemTemplate('SeverityCode', 'SeverityText')}"));
              columns.Bound(x => x.EventCode).Title(Language.SystemEventGridModelTitleEventText).ClientTemplate("#=EventText#");
              columns.Bound(x => x.Date).Title(Language.SystemEventGridModelTitleDate);
              columns.Bound(x => x.IsActive).Title(Language.SystemEventGridModelTitleIsActive);
          .DataSource(binding => binding.Ajax().Read("GetEvents", "Home", null))
          .Pageable(x => x.Refresh(true)))


    The problem is that we can't use the standard filtering for the columns (e.g. EventText) which do not existing in database and are taken from different places:

    Is there a way to apply the filtering for the text and search by code from database?

    P.S. I attached only the source files (models, views and controllers) for the example code.

  2. Answer
    Konstantin Dikov
    Konstantin Dikov avatar
    2124 posts

    Posted 23 Mar Link to this post

    Hello Vangel,

    A possible solution for the scenario that you have is to use the reversed approach over the filter value in the DataSourceRequest object and create a search for the matching EventCode for example:
    public ActionResult Orders_Read([DataSourceRequest]DataSourceRequest request)
        foreach (FilterDescriptor filter in request.Filters)
            if (filter.Member == "EventText")
                filter.Member = "EventCode";
                filter.Value = //get the matching EventCode from the EventText;
        return Json(GetOrders().ToDataSourceResult(request));

    As for the filtering over the EventText field, since it does not exist in the database, you could remove the filters from the request and make custom filtering over the collection.

    Konstantin Dikov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 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