简体   繁体   English

如何在特定列下的 Datatables 中添加新行?

[英]How can I add new rows in Datatables under the specific columns?

I have four ajax calls for four columns, plus some radio buttons for custom query, now on every each selected radio which corresponds to the ajax calls I need the fetched data to be added to the correct column of Datatables, so far, I wrote it like below but it doesn't work.我有四个 ajax 调用四列,加上一些用于自定义查询的单选按钮,现在每个选定的单选按钮对应于 ajax 调用我需要将获取的数据添加到数据表的正确列中,到目前为止,我写了它如下所示,但它不起作用。

   get_available_prefix_request(id, datatable_search){
    fetch(`${this.url['get_available_prefix']}/${id}`)
        .then(response => response.json())
        .then(data => {
            data.forEach(x => {
                datatable_search.row.add(x['address'], '', '', '').draw();
            })
        });
}

get_unavailable_prefix_request(id,datatable_search){
    fetch(`${this.url['get_unavailable_prefix']}/${id}`)
        .then(response => response.json())
        .then(data => {
            data.forEach(x => {
                datatable_search.row.add('', x['address'], '', '').draw();
            })
        });
}

get_unavailable_ip_addresses_request(id, datatable_search){
    fetch(`${this.url['get_unavailable_ip_addresses']}/${id}`)
        .then(response => response.json())
        .then(data => {
            data.forEach(x => {
                datatable_search.row.add('', '', x['address'], '').draw();
            })
        });
}

get_available_ip_addresses_request(id, datatable_search){
    fetch(`${this.url['get_available_ip_addresses']}/${id}`)
        .then(response => response.json())
        .then(data => {
            data.data.forEach(x => {
                datatable_search.row.add('', '', '', x['address']).draw();
            })
        });
}

I would appreciate any help, thanks in advance.我会很感激任何帮助,在此先感谢。

You just need to put your values into square brackets:您只需要将您的值放入方括号中:

datatable_search.row.add(['', '', '', x['address']]).draw();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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