Page 1 of 1

Datagrid- Smooth scrolling of long list

Posted: Wed Mar 11, 2015 11:08 am
by shoshinsha
Hi All,
I have a datagrid with long list of data in a stack.
A scroller is created on opencard to enable scrolling of the datagrid, and then when one of the row is clicked (mouseUp), some actions will be taken (e.g. answer something).

Script on the card:

Code: Select all

on openCard
   send "scroller_create" to me in 0 sec
end openCard

on closeCard
   send "scroller_delete" to me in 0 sec
end closeCard

on scroller_create
   local tScrollerRect, tContentRect
   set the vScroll of grp "listA" to 0
   ##Only create a scroller on a mobile device
   if environment() is not "mobile" then exit scroller_create
   ##Set the area of the scroller
   put the rect of group "listA" into tScrollerRect
   ##Set the area of the content to be scrolled
   put 0,0,(the dgFormattedWidth of group "listA"),(the dgFormattedHeight of group "listA") into tContentRect
   ##Create the scroller control
   mobileControlCreate "scroller", "listScroll"
   put the result into sScrollerID
   ##Set the properties of the scroller
   mobileControlSet "listScroll", "rect",tScrollerRect
   mobileControlSet "listScroll", "contentRect",tContentRect
   mobileControlSet "listScroll", "visible",true
   mobileControlSet "listScroll", "scrollingEnabled",true
   mobileControlSet "listScroll", "vIndicator",true
   mobileControlSet "listScroll", "vscroll", 0
end scroller_create

on scroller_delete
   if environment() is not "mobile" then exit scroller_delete
   mobileControlDelete sScrollerID
end scroller_delete

on scrollerDidScroll hOffset, vOffset
   set the DGvScroll of group "listA" to vOffset
   set the DGSelectedLine of group "listA" to empty
end scrollerDidScroll

on mouseRelease
   set the dgHilitedLines of group "listA" to empty
end mouseRelease
Script in the datagrid behaviour:

Code: Select all

on mouseUp
   put the dgHilitedLines of group "listA" into theLine
   put the dgDataOfLine[theLine] of group "listA" into pData
   ##Some functions
   ....
end mouseUp
My problem is that as I pressed and scrolled the datagrid and released, it was often being detected as "mouseUp" (and actions were taken), even though I was just releasing my finger from scrolling.

I wonder if there is any control that I should take care of, so that as I am scrolling the datagrid it won't trigger mouseUp?

Thank you.

Re: Datagrid- Smooth scrolling of long list

Posted: Wed Mar 11, 2015 3:37 pm
by dunbarx
Hi.

The scrollbars in a DG are named "scrollbar "dgHScrollbar" and scrollbar "dgScrollbar".

You could place an empty "mouseUp" handler in each of those scrollbars to trap and bury the message.

Craig Newman

Re: Datagrid- Smooth scrolling of long list

Posted: Thu Mar 12, 2015 7:46 am
by shoshinsha
Thanks, Craig!
I've placed the handlers on each scrollbar "dgHScrollbar" and scrollbar "dgScrollbar", but still no luck ;(

Code: Select all

on mouseUp
   ##do nothing
end mouseUp

on mouseRelease
   ##do nothing
end mouseRelease

Re: Datagrid- Smooth scrolling of long list

Posted: Thu Mar 12, 2015 2:44 pm
by sritcp
Hi shoshinsha:

Try this in the data grid script:

Code: Select all

local sStartPosition
on mouseDown
put the vScroll of grp "listA" into sStartPosition
end mouseDown

on mouseUp
   if the vScroll of grp "listA" <> sStartPosition then exit mouseUp
   # followed by your usual code
   put the dgHilitedLines of group "listA" into theLine
   put the dgDataOfLine[theLine] of group "listA" into pData
   ##Some functions
   ....
end mouseUp
Regards,
Sri

Re: Datagrid- Smooth scrolling of long list

Posted: Tue Mar 17, 2015 11:03 am
by shoshinsha
Hi Sri,

Thanks for the script! I've made some modification to make the scrolling+selection work:

Code: Select all

local sStartPosition

on mouseUp
   if the DGvScroll of grp "listA" <> sStartPosition then 
      set the dgHilitedLine of me to empty
      exit mouseUp
   end if
   put the dgHilitedLines of group "listA" into theLine
   ...
end mouseUp

on mouseRelease
   set the dgHilitedLine of me to empty
end mouseRelease

on mouseDown
   put the DGvScroll of grp "listA" into sStartPosition
   pass mouseDown
end mouseDown


Using vScroll on datagrid will return 0 value, so I changed it to DGvScroll. Also added "pass mouseDown", if not datagrid lines can't be "clicked".

Thanks a lot :D

Re: Datagrid- Smooth scrolling of long list

Posted: Tue Mar 17, 2015 2:51 pm
by sritcp
Also added "pass mouseDown", if not datagrid lines can't be "clicked".
I thought "mouseDown" goes to the datagrid components (field, row, ..) first before it went to the Datagrid itself (i.e., a message travels 'up' the object hierarchy). When you pass "mouseDown" in Datagrid script, it then goes to the card, I'd guess.

Regards,
Sri

Re: Datagrid- Smooth scrolling of long list

Posted: Wed May 25, 2016 3:07 pm
by MWCoastMedia
I had to modify the location of this slightly for use in LC8. Rather than placing the mouseUp/Down/Release scripts on the group, they need to be placed on the Row Behavior Script (accessed from the Property Inspector, my was labeled 'button "Behavior Script"' when using a form based datagrid).

When I had the code on the datagrid group script, I would get some errant datagrid item selections sometimes when scrolling. All seems good on Android and iOS now. :D