How to access an already created dataTable?
shaunroselt opened this issue · comments
Let's say I have two functions. I create the table in one of the functions and it is localized to that specific function.
And then I have a second function, Is there a way to select the dataTable from that function and do things with it such as dataTable.columns.order([4,3,2,1])
as an example?
function CreatingMyTable(){
let dataTable = new simpleDatatables.DataTable(`#MyTable`, {
searchable: true,
sortable: true,
perPage: 15,
perPageSelect: [5,10,15,20,25,50,100,250,500,1000]
});
}
function DoSomethingWithTable(){
// Initilize or get the dataTable here and then do stuff with it, but I don't want to recreate the table. Just access it.
}
I know I obviously can't just use the let dataTable
variable from the CreatingMyTable
function, but is there a way to create a new variable in my second function and then select the same table inside of it?
I don't want to make a global variable for the table.
No, you have to hand the variable around or make a global variable. Your choice. If we were to add another way of getting it, that would just be some kind of hidden global variable.