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

Viewed 58

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.

   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.

1 Answers

You just need to put your values into square brackets:

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