Changing data source

Changing data source

cersoscersos Posts: 40Questions: 10Answers: 1

I'm trying to dynamically change the data source. For example:

var array1 = array of objects;
var array2 = array of objects;
var array3 = array of objects;
var array4 = array of objects;
var tableData = array1;

var t = $('#myTable').DataTable({'data': tableData,...});

What I'm trying to do is update the data source for the dataTable. For example:

<input type=button value=array1 onClick="tableData=array1; t.clear().rows().invalidate().draw()" />
<input type=button value=array2 onClick="tableData=array2; t.clear().rows().invalidate().draw()" />
<input type=button value=array3 onClick="tableData=array3; t.clear().rows().invalidate().draw()" />
<input type=button value=array4 onClick="tableData=array4; t.clear().rows().invalidate().draw()" />

But, this is not working. Any suggestions?

This question has an accepted answers - jump to answer

Answers

  • cersoscersos Posts: 40Questions: 10Answers: 1
    edited June 2015 Answer ✓

    Figured this one out for myself.

    <input type=button value=array1 onClick="tableData=array1; t.clear().rows.add(tableData).draw()" />

This discussion has been closed.