Page 1 of 1

Using ScrollLineIntoView and ScrollIndexIntoView

Posted: Sat Nov 27, 2010 1:21 am
by exheusden
I have a problem with datagrids with the way that

scrollLineIntoView theLineNumber

works.

When a scroll towards the bottom of the grid is necessary, the line with line number theLineNumber is shown as the bottom line of the grid's field. However, when a scroll towards the top of the grid is needed, the line with line number theLineNumber is shown as the first line in the grid's field.

An example: I have a datagrid filled with some 500 song titles. Suppose it is in its initial state, with the titles beginning with the letter "A" showing in the grid's window and all other titles following these alphabetically. I know the line number of the first title of each letter of the alphabet and have a small script which recognizes a keypress and should position the titles accordingly by scrolling; if the letter "m" is typed, then the first title shown in the grid's field should be the first title starting with that letter, in other words. What happens is one of three things:

1. if no "m" titles are showing, but only titles with a letter earlier in the alphabet, then the grid scrolls so that the first "m" title is shown as the last line of the grid's field;
2. if at least one "m" title is showing, no scrolling at all takes place;
3. if no "m" titles are showing, but only titles with a letter later in the alphabet, then the grid scrolls so that the first "m" title is shown as the first line of the grid's field.

I want the third result to occur always (that the grid scrolls so that the first title beginning with the selected letter appears as the first line in the grid's field). Can this be achieved?


(The explanation above is confusing. I have therefore made a small page, containing visual examples of what happens. It can be found at http://davidneale.eu/livecode/scrolllineintoview.html)

Re: Using ScrollLineIntoView and ScrollIndexIntoView

Posted: Sat Nov 27, 2010 1:04 pm
by Zryip TheSlug
exheusden wrote:I want the third result to occur always (that the grid scrolls so that the first title beginning with the selected letter appears as the first line in the grid's field). Can this be achieved?
Hi Exheusden,

Why not reset the scroll position before to go at the indexed position of the first letter?

command goToMyIndexedLine pTheIndex
dispatch "scrollLineIntoView" to grp "myDatagrid" with 1 -- reset the scroll at the top of the list
dispatch "scrollLineIntoView" to grp "myDatagrid" with pTheIndex
end goToMyIndexedLine

Note that with this way, scrolling at the top of the first letter of an index will only be possible if you have a sufficient amount of data at the end of the grid.

Example: you have a grid with 100 records and your grid manages 10 visibles rows. The user is already at the end of a list displaying:

91 x
92 y
93 y
94 y
95 y
96 y
97 z
98 z
99 z
100 z

For example, if the user search for the z lines, it will be not possible to have the first z line at the top of the visible lines because the user has reached the end of the list.


Regards,

Re: Using ScrollLineIntoView and ScrollIndexIntoView

Posted: Sat Nov 27, 2010 2:51 pm
by exheusden
Thank you, Zryip TheSlug.

Your suggestion results in result 1. However, by setting the scroll initially to the last line and then going to the requested line, result 3 can be obtained.