【问题标题】:datatable yadcf plugin init() not working数据表 yadcf 插件 init() 不工作
【发布时间】:2015-04-09 09:00:10
【问题描述】:

我正在使用带有 bootstrap3 的数据表。我想在单击按钮后应用过滤器。但是当我单击按钮时,它给了我TypeError: oTable.settings is not a function 错误。我的数据表版本是1.10.6,yadcf 版本是0.8.7 这是我的代码

function init_datatable(table_id, records) {
//    console.log('init table',$.parseJSON(records));
    var oTable = $(table_id).dataTable({
        aaData: $.parseJSON(records),
        "sPaginationType": "bootstrap",
        "bFilter": false,
        "bInfo": false,
        "sPageButtonActive": "active",
        "aaSorting": [[0, 'desc']],
        "bDeferRender": true,
        "sDom": '<"top"if>rt<"bottom"lp><"clear">',
        "aLengthMenu": [
            [10, 20, 30, 50, -1],
            [10, 20, 30, 50, "All"] // change per page values here
        ],
        "iDisplayLength": 10,
        "oLanguage": {
            "sEmptyTable": "No data available"
        },
        "aoColumnDefs": [{
                "aTargets": [0],
                "bVisible": false,
                "bSearchable": false
            },
            {
                "bSortable": false,
                "aTargets": [-1], // <-- gets last column and turns off sorting
                "mData": null,
                "mRender": function(data, type, full) {
                    return '<a data-original-title="Edit" id="edit_' + full[0] + '" data-placement="top" class="btn btn-xs btn-teal tooltips edit"  href="javascript:void(0)"><i class="fa fa-edit"></i> Edit</a>';
                }
            }]
    });
//            .yadcf([
//        {column_number: 1}
//    ]);
    $(table_id + '_wrapper .dataTables_length select').addClass("m-wrap");
    $(table_id + '_wrapper .dataTables_length select').select2();
    return oTable;
}

这是应用列过滤器的代码

var pTable = init_datatable('#tbl_sample', data);
     function apply_column_filter() {
            yadcf.init(pTable, [
                {column_number: 1}
            ]);
    }

“init_datatble 函数中的注释代码正在工作。但是当我使用 init 时它给了我错误

【问题讨论】:

    标签: filter datatable yadcf


    【解决方案1】:

    yadcf.init 应该只用于带有大写 D 的新 API,并且由于您没有使用新 API,因此您应该使用以下方式来初始化 yadcf

    $(table_id).dataTable({
        ......
    }).yadcf([......]);
    

    查看the showcase上的代码sn-ps中的cmets

    //----------------------------------------------
    //Example on how to define a custom filter function
    //this function is goinf to be passesd to yadcf as custom_func parameter value
    //and going to be tested against each value in the column
    //----------------------------------------------
    

    b.t.w 如果您想实用地过滤某些列,您应该使用

    exFilterColumn函数,see docs

    【讨论】:

      【解决方案2】:

      您仍然可以通过获取表引用来使用“yadcf.init”。这就是如何获得表的引用:

      var api = new jQuery.fn.dataTable.Api(settings); var oTable = api.table();

      yadcf.init(oTable, [ {}]);

      【讨论】:

        猜你喜欢
        • 2014-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多