yadcf插件-使用带有custom_func的select filter_type

问题描述 投票:0回答:1

使用yadcf插件,是否可以让“ select” filter_type带有为custom_func定义的自定义函数来执行过滤/匹配?

yadcf
1个回答
0
投票

例如

var table = $('#sample-table');
var dtable = table.DataTable();

yadcf.init(dtable, [{
    column_number: 0,
    select_type: "chosen",
    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;
    });
}

阅读文档

* filter_type
            Required:           false
            Type:               String
            Default value:      'select'
            Possible values:    select / multi_select / auto_complete / text / date / range_number / range_number_slider / range_date / custom_func / multi_select_custom_func / date_custom_func
            Description:        The type of the filter to be used in the column


* custom_func
            Required:           true (when filter_type is custom_func / multi_select_custom_func / date_custom_func)
            Type:               function
            Default value:      undefined
            Description:        should be pointing to a function with the following signature myCustomFilterFunction(filterVal, columnVal, rowValues, stateVal) , where `filterVal` is the value from the select box,
                                `columnVal` is the value from the relevant row column, `rowValues` is an array that holds the values of the entire row and `stateVal` which holds the current state of the table row DOM
                                , stateVal is perfect to handle situations in which you placing radiobuttons / checkbox inside table column. This function should return true if the row matches your condition and the row should be displayed) and false otherwise
            Note:               When using multi_select_custom_func as filter_type filterVal will hold an array of selected values from the multi select element
© www.soinside.com 2019 - 2024. All rights reserved.