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

Contains filter on a values lookup column

2 Answers 941 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 13 Apr 2016, 05:58 AM

Is there a way to use a contains filter on a grid column that is using the 'values' lookup attribute? I've noticed with filterable:true option that it does not include a contains option by default. I have a column defined in the columns section of grid options:

{ field: "sampleId", title: "Sample Item", width:165, values: sampleListLookup },

Later a filter as:

filter.push({
           logic: 'or',
           filters:[
{ field: 'sampleId', operator: 'contains', value: $scope.filters.searchString },

However, when I try this is give an error in the Int stored in the column instead of filtering on string values that match the Id key. The logic works very well for string columns, just not the string look-ups above.

Looking for ideas on a work around or is it going to end up being a server side query? Perhaps filtering the lookup lists and passing in the resulting list to the filter?

2 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 14 Apr 2016, 02:54 PM

Hello Tim,

Indeed when foreign key is used (values is set for the column) operations such sorting, filtering are performed against the underlying model values. In this case this will be "sampleId", which is integer. My suggestion is to take a look at the Enable ForeignKey Column Sorting by Text and use this approach for filtering instead. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Tim
Top achievements
Rank 1
answered on 25 May 2016, 09:50 PM

Thank you for the reply. I had skipped this features as a known bug our our application and just got back to it. This solution worked perfectly! For any others that may run into this post looking for a similar solution, here is what I did based on this suggestion, following the link above is great for getting the column up and sort ready. Here is the format for using filters where the calculated column I am using is 'TableName()':

var filter = [];
     if ($scope.filters.searchString != "") {
          filter.push({
              logic: 'or',
              filters:[
                  { field: 'ProductName', operator: 'contains', value: $scope.filters.searchString },
                  { field: 'CategoryName()', operator: 'contains', value: $scope.filters.searchString }
              ]
          });
     }

     $scope.dsSource.filter(filter);

 

 

Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Tim
Top achievements
Rank 1
Share this question
or