简体   繁体   中英

datatable yadcf plugin init() not working

i am using datatable with bootstrap3. i want to apply filter after button is clicked. but when i clicked button it gives me TypeError: oTable.settings is not a function error. my datatable version is 1.10.6 and yadcf version is 0.8.7 here is my code

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;
}

here is code for apply column filter

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

commented code in "init_datatble function is working. but when i use init it gives me error

yadcf.init should be use only for the new API with the capital D and since you are not using the new API, you should use the following way to init yadcf

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

See comments in the code snippets on the showcase

//----------------------------------------------
//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
//----------------------------------------------

btw if you want to filter some column pragmatically you should use the

exFilterColumn function , see docs

You can still use "yadcf.init" by getting the table reference. And this is how can get the reference of a table:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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