Search code examples
kendo-gridkendo-ui-angular2

Custom Grid Filtering Expressions


Quick project background: I am porting some Telerik for ASP.NET grids/back end data sources to Kendo angular UI framework.

Problem: I'm trying to implement grid filtering (has to be custom since I manually bind to handle complex paging/data retrieval.

  1. Is there any method/function to retrieve a filter string instead of the object model containing filters and operators? (I can, obviously, flatten this myself, but it's a bit of code). Here is a code snippet...

if (filter !== undefined) {
            // Step through column filters
            filter.filters.forEach((element: any) => {
                // console.log(element);

                // Step through individual filter for column
                element.filters.forEach((curFilter: any) => {
                    console.log(curFilter.field);
                    console.log(curFilter.operator);
                    console.log(curFilter.value);
                });
            });
        }

  1. I'm still using the dynamic linq queries that the .NET grid used for its filter expressions. Will the filter expressions that come out of grid.filters work correctly with a linq dynamic query on the back-end or will I need to convert?

I feel like I'm missing something here so I thought I'd start a conversation.

Thanks! -Brian


Solution

  • I believe based on your comment answer what you are attempting to do is get the filters and sorts, paging just like its sent for MVC on the network.

    For kendo to do this you need to set your data source type and have the right file included in your page.

    the file name is kendo.aspnetmvc.js or kendo.aspnetmvc.min.js

    and your data source initialization should specify

    dataSource: {
       transport: {
          type: 'aspnetmvc-ajax'
       }
    }
    

    or do the same thing are they are doing

    the cdn for this script is https://kendo.cdn.telerik.com/2018.1.221/js/kendo.aspnetmvc.min.js

    I know they use the like of this functions to do what you are talking about

    function serializeFilter(filter, encode) {
                if (filter.filters) {
                    return $.map(filter.filters, function (f) {
                        var hasChildren = f.filters && f.filters.length > 1, result = serializeFilter(f, encode);
                        if (result && hasChildren) {
                            result = '(' + result + ')';
                        }
                        return result;
                    }).join('~' + filter.logic + '~');
                }
                if (filter.field) {
                    return filter.field + '~' + filter.operator + '~' + encodeFilterValue(filter.value, encode);
                } else {
                    return undefined;
                }
            }