Search code examples
jquerydjangoyadcf

YADCF multi_select filter dropdown element matching as exact match or startsWith match


I'm using yadcf with server side processing in django:

The initialisation of the filter I'm trying to work with is like this :

 { column_number : 4, filter_type: "multi_select", select_type:"select2", sort_as:"none", filter_match_mode:"exact" },

Basically I want the search value entered by the user to be matched with the elements in the drop down list as a "startsWith" or an "exact" match but currently they are being matched as "contains".

This is related to just the matching in the dropdown list and the value entered in the input box on top and not the actual filtering of the table.

and the kind of behaviour i'm looking for can be found here : https://select2.github.io/examples.html#matcher


Solution

  • Here's my work around for the issue, not really sure if this is the right way of doing it but it works for my application -

            $.fn.select2.amd.require(['select2/compat/matcher'], 
          function (oldMatcher) {
                  function matchStart (term, text) {
                      if (text.toUpperCase().startsWith(term.toUpperCase())) {
                      return true;
                   }
                return false;
          }
    
    
        yadcf.init(dt_table, [
        {
          column_number : 0, 
          filter_type:"multi_select",
          select_type:"select2", 
          select_type_options:{ 
             matcher:oldMatcher(matchStart)}
              },
        });