I had meant that there could be modifications to the order that are not the
result of sorting, but now that I think about that, they wouldn't be
reflected in the sortIndexes unless there were a subsequent sort, so you're
right, sortIndexes isn't the definitive source for row ordering.  In any
case, this solution works for me right now.

Thanks again for the guidance on this problem.

It would be great if the API supported taking the entire sortInfo as
returned by getSortInfo in the configuration options, and perhaps the
selection state returned by getSelection too.

David

On Thu, Sep 24, 2015 at 7:52 AM, 'Daniel LaLiberte' via Google
Visualization API <google-visualization-api@googlegroups.com> wrote:

> Thanks for posting your code, and your update.  Preserving and restoring
> the entire row order is certainly simpler and faster than what I was
> suggesting.
>
> But one potential limitation comes up if the data can be changed,
> including the adding or removing of rows.  I thought that was what you
> wanted to support.  In that situation, it may not be correct to apply the
> previous row order to the current table, whereas reapplying the sorting of
> a sequence of columns would always work, though it would certainly be more
> time consuming than merely setting the row order.
>
> An option, or at least a method, to specify the entire sort info would be
> possible.  I'll see about adding that.
>
> On Thu, Sep 24, 2015 at 12:32 AM, David Manz <superm...@gmail.com> wrote:
>
>> Here's an improved version:
>>
>> http://jsfiddle.net/p96x6pxz/2/
>>
>> It maintains entire sort state (not just the last sort) and selection
>> state across redraws.
>>
>> David
>>
>>
>> On Fri, Aug 28, 2015 at 9:20 PM, David Manz <superm...@gmail.com> wrote:
>>
>>> 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 <google-visualization-api@googlegroups.com> 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 <superm...@gmail.com>
>>>> 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 google-visualization-api+unsubscr...@googlegroups.com.
>>>>> To post to this group, send email to
>>>>> google-visualization-api@googlegroups.com.
>>>>> 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
>>>> dlalibe...@google.com <dlalibe...@google.com>   5CC, Cambridge MA
>>>> daniel.lalibe...@gmail.com <daniel.lalibe...@gmail.com> 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
>>>> google-visualization-api+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to
>>>> google-visualization-api@googlegroups.com.
>>>> 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 google-visualization-api+unsubscr...@googlegroups.com.
>> To post to this group, send email to
>> google-visualization-api@googlegroups.com.
>> 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/CAHHNhWrkKdjqZpzHRxa9ZDfqJrVki%2BZ%3DSoA%2BqyhLJHq8Ao_qkA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/google-visualization-api/CAHHNhWrkKdjqZpzHRxa9ZDfqJrVki%2BZ%3DSoA%2BqyhLJHq8Ao_qkA%40mail.gmail.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
> dlalibe...@google.com <dlalibe...@google.com>   5CC, Cambridge MA
> daniel.lalibe...@gmail.com <daniel.lalibe...@gmail.com> 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
> google-visualization-api+unsubscr...@googlegroups.com.
> To post to this group, send email to
> google-visualization-api@googlegroups.com.
> 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/CAOtcSJPv%3Dnto7jytf3zRujRKwicxWi_%2BJVcOrqZw%2B%3DOtwvRrtA%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJPv%3Dnto7jytf3zRujRKwicxWi_%2BJVcOrqZw%2B%3DOtwvRrtA%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 google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
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/CAHHNhWojCNkk3KXnf7HbUXo7ppjOJom-dAfceMFGR7WvKzGMUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to