datatables.mark.js icon indicating copy to clipboard operation
datatables.mark.js copied to clipboard

Support RegExp search

Open julkue opened this issue 8 years ago • 17 comments

As users can search a table with a custom RegExp using e.g. the regex boolean, datatables.mark.js should also handle it as RegExp. In order to implement this, it's necessary to determine if a search was done using the regex option. As there is currently no method to detect this (see this comment), we'll need to wait for a release that implements such method.

This will resolve https://github.com/DataTables/Plugins/issues/136

julkue avatar Jul 10 '16 08:07 julkue

The same problem is when you use the exact match selector "part1 part2" (space between). Nothing highlighted despite the results.

robertwebdev avatar Nov 03 '16 15:11 robertwebdev

@aleyazda please open a new issue and provide a fiddle because there are several options to affect that behavior

julkue avatar Nov 03 '16 17:11 julkue

Hi @DataTables, is there anything new on a method to detect if a search was done using the regex option?

julkue avatar Dec 22 '16 13:12 julkue

No sorry. Its in the private settings object, but isn't currently available via the public API.

DataTables avatar Dec 22 '16 13:12 DataTables

Is there anything I can do to speed this up, e.g. providing a PR?

julkue avatar Dec 22 '16 13:12 julkue

I really need to sit down sometime and design what I want the new API for the search to look like. This probably won't come until the next major release of DataTables (be it 1.12 or 2.0 - haven't decided yet!).

In the short term what you could do is create a plug-in API method that would read the information you need from the private settings object. The oPreviousSearch parameter in the settings object contains the information you need (specifically in its bRegex property. Your plug-in function could just return that.

DataTables avatar Dec 23 '16 10:12 DataTables

@DataTables Thanks for your reply. Unfortunately I don't think that this might solve the problem. If I'm right oPreviousSearch only indicates the settings used for the last search. The plugin on the other hand is able to handle global or column specific searches. This means that if a user searches in two columns I would only be able to retrieve the information for one column. Am I right?

julkue avatar Dec 23 '16 13:12 julkue

oPreviousSearch contains information about the global search that is currently applied to the table. Information about the search applied to each column is in the aoPreSearchCols property - which is basically just an array of object matching the structure of the oPreviousSearch one.

Allan

DataTables avatar Dec 23 '16 14:12 DataTables

@julmot Related, I am trying to support both global search and column search in the same grid, and your highlighter thwacks the global search highlighting. I will whip up a demo later today, but just thought to see if you have a proof-of-concept of using both searches simultaneously.

jzabroski avatar Feb 07 '17 14:02 jzabroski

@jzabroski Thanks for reporting. Since this isn't related to this issue, please create a new one.

julkue avatar Feb 07 '17 14:02 julkue

Any news on supporting regex option with datatables.mark.js searching: true, search: { regex: true },

Here is an exemple: https://jsfiddle.net/PBrockmann/zh8006zr/ If you search for 'rancis' you get all San Francisco and highlights If you search for 'ran.is' you get all San Francisco but no highlights

PBrockmann avatar Jun 18 '18 13:06 PBrockmann

@DataTables

No sorry. Its in the private settings object, but isn't currently available via the public API.

Did this change in the last two years?

julkue avatar Jun 18 '18 17:06 julkue

No sorry. I guess a workaround would be to use an API plug-in which can read the private property. Do you want the global property or per column?

DataTables avatar Jun 18 '18 19:06 DataTables

@DataTables Both, because both is possible and highlighting should behave the same.

julkue avatar Jun 18 '18 22:06 julkue

This should do it:

$.fn.dataTable.Api.register("search.isRegex()", function() {
  var ctx = this.context;

  return ctx.length !== 0 ? ctx[0].oPreviousSearch.bRegex : undefined;
});

$.fn.dataTable.Api.registerPlural(
  "columns().search.isRegex()",
  "column().search.isRegex()",
  function() {
    return this.iterator("column", function(settings, column) {
      var preSearch = settings.aoPreSearchCols;

      return preSearch[column].bRegex;
    });
  }
);

Very simple live example: http://live.datatables.net/mazorupe/1/edit .

DataTables avatar Jun 19 '18 08:06 DataTables

@DataTables Thanks for this example 👍 Finally, can you please point out a reference to the .register() method as I couldn't find it (https://datatables.net/reference/type/DataTables.Api). I'd like to slightly modify your example to use ES6 (especially arrow functions instead of function, therefore I need to know the available parameters).

julkue avatar Jun 19 '18 11:06 julkue

Its documented here.

DataTables avatar Jun 19 '18 12:06 DataTables