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

Grid Filtering on null DropDownList Item

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Don
Top achievements
Rank 1
Don asked on 05 Dec 2014, 06:06 PM
I am trying to filter the Grid based on what the user types.  One of my fields is a drop down list and if the foreignKey ID is null the filter breaks because it cannot get the value.  

The field is Gender.  Is there a way to first check if Gender_Id is null before I check Gender_Types.Gender?  Because if Gender_Id is null then so is Gender_Types.

Here is my code:



// Filter the Grid as a user types
    $("#Search").on("keyup click input", function () {
        grid = $("#Grid").data("kendoGrid");
        var searchFilter = { logic: "and", filters: [] };

        if (this.value.length > 0) {
            var search = this.value.trim();
            var search_array = search.split(" ");
            for (var i = 0; i < search_array.length; i++) {
                var filter = { logic: "or", filters: [] };

                filter.filters.push({ field: "Full_Name", operator: "contains", value: search_array[i] });
                filter.filters.push({ field: "Gender_Types.Gender", operator: "contains", value: search_array[i] });

                searchFilter.filters.push(filter);
            }

            grid.dataSource.query({ filter: searchFilter });

            // When done filtering select page one otherwise no page is selected
            grid.dataSource.page(1);

        } else {
            grid.dataSource.query({ filter: searchFilter });

            // When done filtering select page one otherwise no page is selected
            grid.dataSource.page(1);
        }
    });











1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 09 Dec 2014, 01:17 PM
Hello Donald,

Filtering/grouping/editing etc. on a nested field is not really supported - we strongly recommend to flatten the data before showing it into the Grid.

What kind of dataSource operations do you use? Do you use serverFiltering set to true or to false?

In case you are using server side operation you can implement custom filtering and handle that null checking logic manually.

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/custom-binding#custom-ajax-binding

If using client side operations you can try to filter with a custom operator:

http://www.telerik.com/forums/custom-filtering-7b617857877c#prkw13DE9E2pMvYMcx-6Hg

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Don
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or