【问题标题】:nested dropped down filters with yadcf select2 and dataTables带有 yadcf select2 和 dataTables 的嵌套下拉过滤器
【发布时间】:2018-10-12 18:09:16
【问题描述】:

我已经成功使用 dataTables+yacdf+select2 组合有一段时间了。现在我正在努力将我的 select2 转换为一个有序的缩进下拉列表,其中 optgroup 也可选择(https://select2.org/options,“分层选项”,Selectable optgroups in 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 一起使用?

【问题讨论】:

    标签: datatables jquery-select2 yadcf


    【解决方案1】:

    你应该使用 data_as_is: true , read docs for more info

    • data_as_is 必需:假 类型:布尔值 默认值:假 说明:当设置为 true 时,数据属性的值将按原样输入过滤器(不进行任何修改/修饰)。 当您想为过滤器定义自己的过滤器时非常适合使用 注意:目前受 select / multi_select 过滤器支持

    【讨论】:

    • 丹尼尔感谢您的调查。在发布问题之前,我确实尝试使用 data_as_is: False 。不幸的是,当我通过带有 data_as_is: False 的 yadcf 以 select2 数组格式(如下)提供数据时,select2 似乎根本看不到它。当我绕过 yadcf 直接将它提供给 select2 元素时,它会显示出来。 var data = [ { id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' } ];
    • 通过查看 yadcf 源代码找到了答案。需要通过 yadcf 向 select2 提供数据,格式如下: data: [ ""]
    • @StanK "当您想为过滤器定义自己的 时非常适合使用"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-05
    • 2018-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多