带有 yadcf select2 和数据表的嵌套下拉过滤器



我已经成功地使用dataTables+yacdf+select2组合有一段时间了。现在我正在努力将我的 select2 转换为具有可选选项组的有序缩进下拉列表(https://select2.org/options,"分层选项",Select2 中的可选选项组(。

但是使用 yacdf,我似乎无法以分层格式将数据传递给 select2,如下所示:

var data = [
{ 
"text": "Group 1", 
"children" : [
{
"id": 1,
"text": "Option 1.1"
},
{
"id": 2,
"text": "Option 1.2"
}
]
},
{ 
"text": "Group 2", 
"children" : [
{
"id": 3,
"text": "Option 2.1"
},
{
"id": 4,
"text": "Option 2.2"
}
]
}];

以前的工作代码是:

.yadcf([{column_number: 1, filter_type: "multi_select", select_type: 'select2', filter_container_id: "someFilter2", filter_default_label: "Select xxx", filter_reset_button_text: false, style_class: "form-control", 
select_type_options: {
multiple: 'multiple',
width: '100%',
placeholder: 'something',
},
data: [<comma separated list of values>]

YACDF源代码指出:

Required:           false
Type:               Array (of string or objects)
Description:        When the need of predefined data for filter is needed just use an array of strings ["value1","value2"....] (supported in select / multi_select / auto_complete filters) or array of objects [{value: 'Some Data 1', label: 'One'}, {value: 'Some Data 3', label: 'Three'}] (supported in select / multi_select filters)

注意:当filter_type custom_func/multi_select_custom_func时,此数组将填充自定义过滤器选择元素 ">

真的不可能吗? 如果没有人设法让嵌套的下拉过滤器以其他方式与 dataTables 一起工作?

您应该使用data_as_is: true,阅读文档以获取更多信息

  • data_as_is 必需:假 类型:布尔值 默认值:假 描述:设置为 true 时,data 属性的值将按原样输入筛选器(无需任何修改/修饰(。 当您想为过滤器定义自己的过滤器时,非常适合使用 注意:目前受选择/multi_select过滤器支持

最新更新