Contains filter on a values lookup column

3 posts, 0 answers
  1. Tim
    Tim avatar
    19 posts
    Member since:
    Jul 2014

    Posted 13 Apr 2016 Link to this post

    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. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 14 Apr 2016 Link to this post

    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!
     
  3. Tim
    Tim avatar
    19 posts
    Member since:
    Jul 2014

    Posted 25 May 2016 in reply to Boyan Dimitrov Link to this post

    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);

     

     

Back to Top