I just want to sort the column 0 descending. I am using this code:
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
containerId: 'chart_table_a',
options: {
sortColumn: 0,
sortAscending: false,
sort: 'enable'
}
});
I don't want to make the table sortable, but the code only works with sort: 'enable'
.
Is there a way to just sort without make the table sortable?
Sort your DataTable:
// sort by column 0, descending
data.sort({column: 0, desc: true});
or use a sorted DataView:
var view = new google.visualization.DataView(data);
view.setRows(data.getSortedRows({column: 0, desc: true}));
table.draw(view, options);
Sorting the DataTable modifies the actual order of the data, and will affect other charts/tables that use the DataTable. This can be expensive in terms of CPU usage if the DataTable contains a large number of rows. Using a DataView preserves the data in the original DataTable (at the expense of a small increase in memory use), and is comparatively cheap in terms of CPU time, but if your DataTable isn't huge or you don't have any other charts that rely on it, you're probably safe just sorting the base DataTable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With