table.columns is not a function in datatable.js

前端 未结 8 1641
鱼传尺愫
鱼传尺愫 2021-02-01 13:12



        
8条回答
  •  广开言路
    2021-02-01 13:40

    I was trying this with a makeEditable() function of dataTables. If I change dataTables() with DataTables() it doesn't work.

    The answer of h0mayun works for me. Just in case if someone else search for this problem I'm adding a little thing with h0mayun's comments.

    var table = $('#sample_3').dataTable();
    $('#sample_3 tfoot th').each(function (i) 
    {
    
                var title = $('#sample_3 thead th').eq($(this).index()).text();
                // or just var title = $('#sample_3 thead th').text();
                var serach = '';
                $(this).html('');
                $(serach).appendTo(this).keyup(function(){table.fnFilter($(this).val(),i)})
    });
    

    And remove the following part

    // Apply the filter
            table.columns().eq(0).each(function (colIdx) {
    
                $('input', table.column(colIdx).footer()).on('keyup change', function () {
    
                    table
                        .column(colIdx)
                        .search(this.value)
                        .draw();
                });
            });
    

    Hope it'll help someone.

提交回复
热议问题