Daniel, Thank you for your guidance--it was very helpful.
I considered your idea of keeping the history of sorts and then replaying them upon a redraw, but that's a bit complicated and it is conceivable that the order of rows could change in response to events other than sorting--the Netflix DVD queue would be an example of that,--and then you'd still have a problem. What I ended up doing was to persist the sortIndexes returned by getSortInfo. The one tricky part is that redrawing the table resets getSortInfo's frame of reference, so I have to keep around an alias table to translate between the current frame of reference and the original one. I also use getSortInfo's sortColumn and sortAscending in the redraw so as to preserve the visual indicator of the most recent column sorted. As long as the sort algorithm is a stable one, this doesn't cause any problems. Here's my code with a small test case. https://jsfiddle.net/w9scudwm/1/ To see the original problem, just comment out the tableDataView.setRows line, and then on the table sort by row number descending, sort by parity, and then click 'redraw'. If you do make a change to the google visualizations api, I think it would make sense for the draw method to take the entire state returned by getSortInfo as an option instead of just the sortColumn and sortAscending attributes. David On Fri, Aug 28, 2015 at 9:23 AM, 'Daniel LaLiberte' via Google Visualization API <[email protected]> wrote: > At this point, yes, you'll have to manage the sorting yourself, which > would probably be easiest using getSortedRows() and constructing a DataView > with those rows using setRows(). > > The Table chart only knows about one column for sorting so it can indicate > that column in the header; it also supports sorting by any columns > interactively, of course. > > If you want to keep the same ordering after the user does several sort > operations, then you'll want to get the 'sort' events as they occur, do the > sort yourself as you save the columns in an array that you can later use to > sort another DataTable. One problem is deciding how many sort steps to > remember, if not all steps. Repeatedly sorting the same column, which > reverses the previous sort, could be abbreviated to the last one. But > sorting subsequent columns depends on the order determined by all the > previous sorts, potentially. > > We could allow the sort column option (or sortColumns) to be an array, in > which case, it would sort of each of those columns in order. And then we > could also maintain the order of the columns sorted by the user, and return > that array to you so you could apply the same ordering to another > DataTable. This would be doing all the work that you will have to do > yourself currently, so if you end up doing that, post your code, and maybe > we will be able to use it. > > > On Fri, Aug 28, 2015 at 10:02 AM, David Manz <[email protected]> wrote: > >> I have a table with multiple sortable columns and dynamic data. When the >> data in the table is updated, I need to redraw the table, and I would like >> to maintain the sort state across the redraw. However, it appears to me >> that there is no way to do this without actually modifying the order of the >> underlying data--mixing the model and the view. Table and DataView both >> allow me to get the entire sort state of the table, but when I want to >> restore it, I am only allowed to specify a single column to sort by, which >> is insufficient. DataTable allows a full specification of the sort state. >> Is that how I am supposed to maintain sort state? >> >> David >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Visualization API" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to >> [email protected]. >> Visit this group at >> http://groups.google.com/group/google-visualization-api. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/google-visualization-api/fc5f399b-7bb3-4203-82d9-9ef837c4cd20%40googlegroups.com >> <https://groups.google.com/d/msgid/google-visualization-api/fc5f399b-7bb3-4203-82d9-9ef837c4cd20%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> > - 978-394-1058 > [email protected] <[email protected]> 5CC, Cambridge MA > [email protected] <[email protected]> 9 Juniper Ridge > Road, Acton MA > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Google Visualization API" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/google-visualization-api/S_6dZOlNph4/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To post to this group, send email to > [email protected]. > Visit this group at > http://groups.google.com/group/google-visualization-api. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJOAPYoFMY39UJNoS0X0nDmR89VH8in1h%2BycmvrECBKYyg%40mail.gmail.com > <https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJOAPYoFMY39UJNoS0X0nDmR89VH8in1h%2BycmvrECBKYyg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/CAHHNhWoseahveYmgDwXk1SVzfV3TsNqf2UCrsNPLNHAjHM%2B-RQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
