Datagrid best practise

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Datagrid best practise

Post by malte » Fri Mar 09, 2012 1:21 pm

Pretty green to LC on iOs this far, I could use a hand.

I want a datagrid. I want to be able to scroll it with the finger and without a scrollbar.

What is the best practise here? Use a DG at all? Or create a custom scroller?

Any pointers much appreciated.


Malte

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Datagrid best practise

Post by strongbow » Fri Mar 09, 2012 3:29 pm

I use a scroller, catch scrollerDidScroll messages in the card script like so:

Code: Select all

on scrollerDidScroll pOffsetX, pOffsetY
   -- Set the scroll values of the group based on feedback from the scroller
      set the dgVScroll of grp "yourDGName" to pOffsetY
end scrollerDidScroll
HTH

cheers

Alan

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Re: Datagrid best practise

Post by malte » Sat Mar 10, 2012 1:34 am

Thank you Alan,

do you happen to have an example stack?

Cheers,

Malte

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Datagrid best practise

Post by strongbow » Sat Mar 10, 2012 10:11 am

Hi Malte

No good stack to share though I think I found one in these forums. My main scroller creation script is below. The main thing to remember is to use the dgFormattedHeight of grp "yourDataGridName" for finding out the height of the contents of the DG.

i.e.
put the dgFormattedHeight of grp "dgIndex" into tHeight
iphoneControlSet sScrollerId, "contentRect", (0, 0, the width of grp "dgIndex", tHeight)

At the moment it doesn't scroll that smoothly, but I expect that to change when I shift stuff to v. 5 and above and use the dynamic graphic settings - this helped for some other scrolling cases.

HTH... Good luck!

---

Code: Select all

on smCreateScroller
   -- Create the scroller and store its id into local var
   iphoneControlCreate "scroller"
   put the result into sScrollerId
   
   -- The 'rect' is the region of the card it should cover
   iphoneControlSet sScrollerId, "rect", the rect of grp "dgIndex"
   -- The 'contentRect' is the region the scroller scrolls over
   -- for the datagrid, we need to use the "dgFormattedHeight" to get the content height
   put the dgFormattedHeight of grp "dgIndex" into tHeight
   iphoneControlSet sScrollerId, "contentRect", (0, 0, the width of grp "dgIndex", tHeight)
   -- The 'visible' determines if the scroller is displayed
   iphoneControlSet sScrollerId, "visible", "true"
   -- The 'canBounce' determines whether the standard iOS 'bouncing' occurs at extremities of scrolling
   iphoneControlSet sScrollerId, "canBounce", "true"
   -- The 'pagingEnabled' determines whether scrolling only happens in multiples of the width/height
   iphoneControlSet sScrollerId, "pagingEnabled", "false"
   -- The 'canScrollToTop' determines whether touching the status bar scrolls the scroller to the top
   iphoneControlSet sScrollerId, "canScrollToTop", "true"
end smCreateScroller
cheers

Alan

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Re: Datagrid best practise

Post by malte » Sat Mar 10, 2012 12:16 pm

Ah, right... Thank you. Well. the problem if one sets the dg to its formattedheight, is that one looses out on all its main advantages. That is the caching and needing to draw only those parts that are visible! If you have very very long lists (100k + lines) I doubt this will be anywhere near performant enough...

Will have to be thinking about this more. :-(

Thanks anyway.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Re: Datagrid best practise

Post by malte » Sat Mar 10, 2012 12:17 pm

Wait... did I read this completely wrong?

Can the dg be its actual visible height, but the scroller is not?

Thanks again,

Malte

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Datagrid best practise

Post by strongbow » Sat Mar 10, 2012 12:40 pm

Hi Malte

No, you're setting the scroller to cover the rect of the DG, but you set the "contentRect" to the size of the content contained in the DG. Of course, this assumes that you've already populated the DG. If you do some clever stuff with populating it on the fly, then I guess you'll need to do something else. But this seems to work for me, though I only have about 1000 rows in the DG that I'm using, of which between 10 and 30 might be visible...

Does that make sense?

HTH

cheers

Alan

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Re: Datagrid best practise

Post by malte » Sat Mar 10, 2012 1:41 pm

Hi Alan,

a lot of sense. :-)

The good thing about the datagrid is, it does not really matter if it is a thousand or 10 000 lines. I'll give this a try.

Thanks again,

Malte

Post Reply