Initialize Datatables Once

Initialize Datatables Once

INTONEINTONE Posts: 153Questions: 58Answers: 6

I am trying to find a way to do the following. I know it should be easy but I do not know how.
1. Initialize data tables:

table20 = $('#operationsDataTable').DataTable();

then use that instance some where else to accept data and add columns, without having to destroy and reinitialize the table. Something like this:

table20( {
                      "data": data.operationsData,
                      "columnDefs": [{"visible": false, "targets":4} ],
                      "columns": [
                          { "data": "scopeWorkDetailsID" },
                          { "data": "operationDescription" },
                          { "data": "assignedDepartmentText" },
                          { "data": null,"defaultContent":'<a href="#" class="btn btn-warning btn-xs pull-right editor_delete" >Delete</a> <a href="#" class="btn btn-primary btn-xs pull-right button-margin-left-right editor_edit">Edit</a>'},
                          { "data": "assignedDepartment"}           
                      ]
                });

it is very obvious I am a novice to javascript.

This question has an accepted answers - jump to answer

Answers

  • INTONEINTONE Posts: 153Questions: 58Answers: 6

    Well from ready docs it appear this is not possible, to adjust the init on the fry. I either have to use this https://datatables.net/reference/option/retrieve or this https://datatables.net/reference/api/destroy()

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Answer ✓

    then use that instance some where else to accept data and add columns, without having to destroy and reinitialize the table

    Not possible as you have found. You have to define columns upfront. You can add and remove data with the API. But you can't add and remove columns (it is something I plan to add in future, but not likely in the near future).

    Allan

This discussion has been closed.