2

I'm working with the data grid with SQLite database using a feature called callbacks as described in this lesson: displaying-large-amounts-of-data

I'd like to make some changes to the sample stack included in that lesson (you can download the stack from the link on the top of that page).

I'd like to display the 'plot' text in the DG instead of the 'Title' of the movie and the plot text should have variable line heights as described in this lesson: how-do-i-create-a-form-with-variable-line-heights

In the sample stack I made these changes:

in the Row Template: renamed field "Title" to "plot", set the dontWrap to false and changed fixedLineHeight to false

renamed field "ReleaseDate" to "nr"

added: set the text of field "nr" of me to pDataArray["id"]

in the Row Behavior:

    ## changed the layoutControl to make space for wrapping of field "plot"

    on LayoutControl pControlRect
    local theFieldRect

   put the rect of me into theFieldRect
   set the right of button "Genre" of me to item 3 of theFieldRect
   set the right of field "LblGenre" of me to the left of button "Genre" of me

   set the right of field "nr" of me to item 3 of theFieldRect

   ## Expand field "plot"
   put the rect of field "plot" of me into theFieldRect
   put item 3 of pControlRect - 180 into item 3 of theFieldRect
   set the rect of field "plot" of me to theFieldRect

   ##Now resize field to fit content
   put item 2 of theFieldRect \
         + the formattedheight of field "plot" of me - \
         the bottommargin of field "plot" of me \
   into item 4 of theFieldRect
   set the rect of field "plot" of me to theFieldRect

   ## Now update the bounding rect to match total height you
   ## want this row to have
   put item 4 of theFieldRect into item 4 of pControlRect

   set the rect of graphic "Background" of me to pControlRect
end LayoutControl

In the lesson on setting variable line heights it says to turn off the "fixed control height" of the data grid. However when I do that nothing gets displayed and I'm getting a scrip error.

The stack with my changes is here: Databases-callbacks-variable-line-height.zip (just replace the original stack from the lesson with it; the SQLite database is the same and should be placed in the same folder as the stack).

How to fix this so that the variable line height will work?

mark
  • 222
  • 1
  • 9

1 Answers1

1

I located the problem with fixed control height turned off. The data grid behavior isn't setting the GetDataForLine pLine parameter properly when caching the height for each row. I'll provide a modification you can make to the data grid behavior until a fix is included in LiveCode, but you should probably reconsider your approach. When fixed line height is turned off the data grid has to compute the height of every line prior to displaying the data grid. This takes a loooooong time for the 50,000 record example you are working with.

First, edit the script of the data grid behavior:

edit script of btn "data grid" of stack "revdatagridlibrary"

Next, go to line 3097. Below 3097 add the following line of code:

add 1 to theSequence

The code should now look like this:

repeat for each key theIndex in sDataArray     
            add 1 to theSequence

            ## Get height
            if sDataArray[theIndex] is NULL then

Save the script. This will save the change in your current version of LiveCode. Be aware that the next time you update LiveCode the change will be lost. I submitted the fix to RunRev, however, so it should be fixed in the next release.

Also, your code that sets the rect of graphic "Background" needs a small change. Right now it won't work if the bottom of the field is higher than the bottom of the "Genre" button. The code should probably be something like this:

put max(item 4 of theFieldRect, the bottom of button "Genre" of me + 4) into item 4 of pControlRect
  • It works OK now but as you said it's VERY slow to draw the 50000 records list - it took about 5 min. (!) on an Android tablet that is otherwise fast (with just 1100 records it took 7 sec. which is also too slow). So this method is way to slow, but it's good that you tracked the bug. I wanted to test this method mainly to compare the scrolling speed with native Android scroller in my app that I'm working on. It has about 700 records, is using the standard LC data grid which gets its data from a tab delimited text file....continue in next comment. – mark Jul 08 '14 at 04:47
  • The scrolling on that app is slow so I'm searching for different ways to speed it up and make it more responsive. If you have some time to look at my stack (it's self contained without any external files needed) then I would be grateful for any suggestions on how to speed up its scrolling. The link to my app: [DG-only-1.16.zip](https://www.dropbox.com/s/xs0pcrwvh1cc74h/DG-only-1.16.zip) To test its Data Grid srolling click on "Select All", then "Lines" and then "Entire Selection". – mark Jul 08 '14 at 04:50
  • I actually created a new question for the issue of the scrolling speed: [scrolling_speed](http://stackoverflow.com/questions/24627756/how-to-increase-the-speed-of-the-native-android-scroller-for-the-data-grid) ; I forgot to mention in the comments above that the scrolling of the DG with these 50000 records is much better when using the callbacks feature. – mark Jul 08 '14 at 09:12
  • I'll respond to the other question. – Trevor DeVore Jul 08 '14 at 11:22
  • Hi Keram, Trevor informed us of the bugs which has now been fixed. It will go out in the next build of 6.7. – Benjamin Beaumont Jul 08 '14 at 14:50