Paul
Paul

Reputation: 6911

Tag selection in table (rendered_html with filter_match_mode=exact)

I'm using DataTables with yadcf. I'd like to implement tag selection. I found the example here: https://stackoverflow.com/a/35254351/2604492

But it uses filter_match_mode=contains (the default), which means that if there are e.g. two tags, php and not-php, choosing php will match not-php too as the former is contained in the latter.

Example: https://jsfiddle.net/o7hv6qpy/

With filter_match_mode=exact it just stops working.

Any solution?

Upvotes: 1

Views: 128

Answers (1)

Daniel
Daniel

Reputation: 37061

One way to achieve it is to use the custom_func like shown below.

You can put your exact logic into the custom_func implementation

yadcf.init(table, [
    {
    column_number : 1,
    column_data_type: "rendered_html",
    html_data_type: "text",
    filter_default_label: "Select tag",
    text_data_delimiter: ',',
    filter_type: 'custom_func',
    custom_func: myCustomFilterFunction
  }
]);

function myCustomFilterFunction(filterVal, columnVal) {
    const items = columnVal.split(',');
    return items.some(function(arrVal) {
        return filterVal === arrVal;
    });
}

Upvotes: 0

Related Questions