DataTable Setup After Init

DataTable Setup After Init

danchidanchi Posts: 9Questions: 4Answers: 0

Dear,
I'm new in datatables, still learning.
I need help to understand how I can populate my table, after table is initialized ?
On page load,I'm init datatable later based on selection on dropdown, datatable should be populated.
How I can manage this ?
Here is my code at the moment:

  var selectedRows = new Set();
        var table = $('#example').DataTable({
                dom: 't',
                columns: [
                    {
                        data: null,
                        render: function(data) {
                            return `<input type="checkbox" ${selectedRows.has(data.id) ? 'checked' : ''}></input`
                        }
                    },
                    {data:'year',title:'Year'},
                    { data: 'month', title: 'Month' },
                    { data: 'accountId', title: 'Account Number' },
                    { data: 'invoice', title: 'Invoice' },
                    { data: 'payable', title: 'Payable' },
                    { data: 'commitments', title: 'Commitments' },
                    { data: 'iban', title: 'IBAN' },
                    { data: 'name', title: 'Name' },
                    { data: 'referenceNumber', title: 'Reference Number' }
                ]
            });
        $('select').on('change',
            function() {
                $.ajax({
                        type: 'GET',
                        url: 'APICAL[]()',
                        data: { request: this.value },
                        contentType: "application/json; charset=utf-8",
                        success: function(response) {
                            populateDataTable(response);



                        },
                        error: function(response) {
                            console.log(response);
                        }
                    })
                    .done(function(data) {

                    });

            });

How later I can use table variable ?

Thanks

Answers

  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949

    I need help to understand how I can populate my table, after table is initialized ?

    Use rows.add() to add rows to a previously initialized Datatable.

    How later I can use table variable ?

    See the API docs to learn how to access the API.

    Kevin

Sign In or Register to comment.