nityanand

Custom Filter: How to pass multiple values to a field in filter_definition from filter_populate?

Discussion created by nityanand on Sep 11, 2017
Latest reply on Sep 13, 2017 by nityanand

Requirement 1: Custom-Module Records should be filtered based on 'name' field which starts with 'A' OR 'B' OR 'C'. 

 

File path: custom/Extension/modules/custom-Module/Ext/clients/base/filters/basic/filterForQuotes.php

'filter_definition' => array(

   array(

      '$or' => array(

            array(

                     'name' => array( '$starts' => 'A', ),    // 'A' should be dynamically populated

             ),

            array(

                     'name' => array( '$starts' => 'B', ),    // 'B' should be dynamically populated

            ),

            array(

                     'name' => array( '$starts' => 'C', ),    // 'C' should be dynamically populated

            ),

        ),

   ),

),

 

File Path: custom/modules/Quotes/clients/base/fields/custom-relate/custom-relate.js

this._filterOptions = new app.utils.FilterOptions()

 .config({
      'initial_filter': 'filterForQuotes',
      'initial_filter_label': 'LBL_FILTER_FOR_QUOTES',
      'filter_populate': {
            'name': 'A', // how to pass multiple values A/B/C to $or in above filter
                           definition from here?
      }
  })
.format();

 

Requirement 2: Conditionally, filter records where 'name' starts only with 'A' and ignore 'B' and 'C' with the above filter definition.

 

Possible solution that I found:

Adding dynamic filter definition in buildFilterDef( )  method of filter.js

File : custom/clients/base/layouts/filter/filter.js

 

But, is it possible to pass multiple values and ignore certain filters dynamically in filter definition?

Outcomes