alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 361 forks source link

Changing columns #170

Open AndrewMonty opened 9 years ago

AndrewMonty commented 9 years ago

First, thanks for this. I'm fairly inexperienced with javascript, but I've got a sortable, filterable table up and running much faster than I could have imagined.

My columns can change based on user input. Since headers can't be defined by JSON, I'm currently passing the new headers as a string in my response along with the JSON data, and replacing them:

var thHTML = response.headers
$('#results-table>thead').find("tr").remove();
$('#results-table>thead').append("'"+thHTML+"'");

Then

var json = JSON.parse(response.data);
dynatable.settings.dataset.originalRecords = json;
dynatable.process();

This seems to partially work, the data maps to the correct columns, searching and pagination works, however sorting does not. Do I need to initiate a new dynatable when the headers are changed? How would I go about doing that while keeping the same table ID?