table.columns is not a function in datatable.js

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



        
相关标签:
8条回答
  • 2021-02-01 13:44

    It has been a while since this question was asked but I am posting this as it might help someone.

    I had similar issue and after some searching I realized I had to include file located at - http://jquery-datatables-column-filter.googlecode.com/svn/trunk/media/js/jquery.dataTables.columnFilter.js to my code.

    0 讨论(0)
  • 2021-02-01 13:51

    None of the previous answers solved the problem for me.

    The solution I found was using table.api().column(colIdx) instead of table.column(colIdx).

    Working example I developed for a table with names and ages:

        table = jQuery('#sel').dataTable( {
            "initComplete": function( settings, json ) {
                jQuery("#sel_filter").find("input").unbind();
                jQuery("#sel_filter").find("label").after(
                    "<select id='opts'><option value='0'>Name</option>"+
                    "<option value='1'>Age</option></select>");
                jQuery("#sel_filter").find("input").on('keyup change', function(){
                    table.api().columns( jQuery("#opts").val()).search( this.value ).draw();
                });
            },
            "ajax": {
                "url": "urlvalue",
                "type": "GET"
            },
            "columns": [
                { "data": "name" },
                { "data": "age" }
            ]
        });
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题