Override

Override

advaniaadvania Posts: 35Questions: 13Answers: 0

I'm looking to replace the functionality of _fnFilterCreateSearch, I want to change the behavior considerably but of course without having to edit and maintain jquery.dataTables.js.

function _fnFilterCreateSearch( search, regex, smart, caseInsensitive )
  {
    search = regex ?
      search :
      _fnEscapeRegex( search );

    if ( smart ) {
      /* For smart filtering we want to allow the search to work regardless of
       * word order. We also want double quoted text to be preserved, so word
       * order is important - a la google. So this is what we want to
       * generate:
       *
       * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
       */
      var a = $.map( search.match( /"[^"]+"|[^ ]+/g ) || [''], function ( word ) {
        if ( word.charAt(0) === '"' ) {
          var m = word.match( /^"(.*)"$/ );
          word = m ? m[1] : word;
        }

        return word.replace('"', '');
      } );

      search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$';
    }

    return new RegExp( search, caseInsensitive ? 'i' : '' );
  }

Any ideas?

Could I use the plugin API to override ? https://datatables.net/examples/plug-ins/plugin_api.html

I found an old thread speaking of the same issue but suggested then was to edit the datatables source code.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin
    Answer ✓

    The same still applies. There is no method exposed by which the internal functions of DataTables can be modified externally. If you want to change the internal functions you need to change them in the source.

    Allan

  • advaniaadvania Posts: 35Questions: 13Answers: 0

    Thanks Allan, we will be looking into that option then.

This discussion has been closed.