Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery数据表插件列可见性_Javascript_Jquery_Ajax_Datatables - Fatal编程技术网

Javascript JQuery数据表插件列可见性

Javascript JQuery数据表插件列可见性,javascript,jquery,ajax,datatables,Javascript,Jquery,Ajax,Datatables,我定义了这个JQuery数据表: APMTable = $(table).DataTable({ "ajax": { "url": AP.APP_ROOT + '/api/'+ AP.WebId + '/' + AP.BillToCompanyKey + '/' + from + '/' + to + '/' + AP.LocaleId + '/' + material, "type": "GET" },

我定义了这个JQuery数据表:

    APMTable = $(table).DataTable({
        "ajax": {
            "url": AP.APP_ROOT + '/api/'+ AP.WebId + '/' + AP.BillToCompanyKey + '/' + from + '/' + to + '/' + AP.LocaleId + '/' + material,
            "type": "GET"
        },
        columns: [
            { data: "rgNumber" },
            { data: "rgDescription" },
            { data: "rtDescription" },
            { data: "rtNumber" }
        ],
        "responsive": true,
        "order": []
        //"bSort": false
    });

    APMTable.on('xhr.dt',
        function() {
            if (countrycode === 'BR') {
                console.log('SHOW END', countrycode);
                APMTable.column(1).visible(false);
                APMTable.column(2).visible(true);
                APMTable.column(3).visible(true);
            } else {
                console.log('HIDE END', countrycode);
                APMTable.column(1).visible(true);
                APMTable.column(2).visible(false);
                APMTable.column(3).visible(false);
            }
        });
我想隐藏索引1中的列,第2列和第3列显示countrycode是否为“BR”。当然,如果countrycode不是“BR”,则反之亦然

实际情况是,第一次呈现datatable并完成Ajax调用时,值“HIDE END GB”被写入控制台,但没有一列被隐藏

如果我这样称呼:

APMTable.ajax.url( '/api/' + AP.WebId + '/' + from + '/' + to + '/' + LocaleId + '/' + material).load();
Ajax事件监听器再次启动,列隐藏

我很困惑,因为console.log()语句是在尝试隐藏第一列的同时编写的,但没有任何列被隐藏。在呈现列之后,datatable是否触发了一个我不知道的单独事件


我是否需要使用超时使列第一次隐藏,或者是否有其他情况发生?

如果在初始化表之前知道
countrycode
的值,我将重写如下:

APMTable = $(table).DataTable({
    "ajax": {
        "url": AP.APP_ROOT + '/api/'+ AP.WebId + '/' + AP.BillToCompanyKey + '/' + from + '/' + to + '/' + AP.LocaleId + '/' + material,
        "type": "GET"
    },
    columns: [
        { data: "rgNumber" },
        { data: "rgDescription", visible: (countrycode == 'BR' ? false : true ) },
        { data: "rtDescription", visible: (countrycode == 'BR' ? true : false ) },
        { data: "rtNumber", visible: (countrycode == 'BR' ? true : false ) }
    ],
    "responsive": true,
    "order": []
});

我向事件侦听器添加了2000毫秒的超时,并将事件更改为“draw”,在等待2秒后,在第一次加载时,表确实隐藏了这些列。有人能建议对此进行改进吗?您看过datatable dataFilter选项吗?