Sort in Google Table

I just want to sort column 0 in descending order. 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 the table to be sorted, but the code only works with sort: 'enable' .

Is there a way to sort without sorting the table?

+6
source share
1 answer

Sort 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 a DataTable changes the actual order of the data and affects other tables / tables using the DataTable. This can be expensive in terms of CPU usage if the DataTable contains a large number of rows. Using a DataView saves the data in the original DataTable (due to a small increase in memory usage) and is relatively cheap in terms of CPU time, but if your DataTable is not huge or you don't have other diagrams that rely on it, you are probably safe just sorting the base DataTable

+9
source

Source: https://habr.com/ru/post/969588/


All Articles