繁体   English   中英

yadcf 插件 - 使用 select filter_type 和 custom_func

[英]yadcf plugin - using select filter_type with custom_func

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

是的

例如

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM