agusluc
agusluc

Reputation: 1465

Custom sort function in google chart table

I need a google chart table with custom sorting for one of the columns. I created the table with sort: 'event, i guess that this should emit some event that can be captured, but didn't found any information about it.

Upvotes: 3

Views: 1224

Answers (1)

asgallant
asgallant

Reputation: 26340

Capture the "sort" event with an event handler:

// table is your Table visualization
google.visualization.events.addListener(table, 'sort', function (e) {
    // e.column is the column to sort
    // e.ascending is a boolean, true for ascending sort, false for descending sort

    // sort your data

    // if you want the ascending/descending elements to work correctly, you need to specify the Table's sortColumn and sortAscending options when you redraw the Table, eg:
    options.sortColumn = e.column;
    options.sortAscending = e.ascending;
    table.draw(sortedData, options);
});

Upvotes: 1

Related Questions