table.columns is not a function in datatable.js

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



        
8条回答
  •  挽巷
    挽巷 (楼主)
    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(
                    "");
                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.

提交回复
热议问题