Datagrid: Problems with dgdata? [solved]

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Datagrid: Problems with dgdata? [solved]

Post by ittarter » Sun Aug 26, 2018 5:27 pm

Hi everybody.

I've used datagrids dozens of times (rarely is it easy). I've had scrolling problems before but they often "just went away" after closing LC and opening it back up later.

I've created a new datagrid that is behaving very strangely. It's a datagrid form with just two fields plus the background graphic and virtually no code to speak of, other than the essentials. When I update dgdata with the relevant array, the datagrid correctly shows the content of visible records immediately, but then my program becomes unresponsive for about 30 seconds. After the program is responsive again, I can click and highlight individual records, but the scrollbar is deactivated and doesn't work, and sorting by a key (I've tried many iterations) doesn't work. I can get data by line, but not by index, even though dgHilitedIndexes yields the correct index, dgDataOfIndex yields nothing (see below).

I'm baffled about all of this. I've been baffled for a week, and if I'm stuck after a week, which I am, I typically ask you guys for help. Any ideas would be greatly appreciated.

Main handler:

Code: Select all

set the dgdata of group "indicators" to tArrayFiltered
Testing handler in script of datagrid group:

Code: Select all

get the dgHilitedLines of me
   put the dgDataOfLine[it] of me into tData1 --no problem, array shows up as normal
   get the dgHilitedIndexes of me
   put the dgDataOfIndexes[it] of me into tData2 --should be the same data as tData1 but in fact it is empty
Relevant part of dg behavior script:

Code: Select all

on FillInData pArray
   set the text of field "category" of me to pArray["Code"]
   put toupper(pArray["EN title"]) into y
   if the length of pArray["EN description"] < 3 then
      set the text of field "Label" of me to y &  "." && pArray["EN Example"]
   else
      set the text of field "Label" of me to y & "." && pArray["EN description"]
   end if
end FillInData
Layout control is currently empty to avoid any complications but eventually I will use something like:

Code: Select all

on LayoutControl pControlRect
set the rect of graphic "Background" of me to pControlRect
if the formattedheight of fld "label" of me > the height of fld "label" of me then
      put min(the formattedheight of fld "label" of me,100) into x
      set the height of fld "label" of me to x
      set the top of fld "label" of me to the top of graphic "Background" of me
      set the top of fld "category" of me to the top of graphic "Background" of me
      set the height of graphic "Background" of me to x
      set the top of graphic "Background" of me to the top of fld "label" of me
      put the rect of graphic "Background" of me into pControlRect
   end if
end LayoutControl
Last edited by ittarter on Tue Aug 28, 2018 6:00 pm, edited 1 time in total.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid: Problems with dgdata?

Post by Klaus » Sun Aug 26, 2018 6:57 pm

Hi ittarter,

Code: Select all

get the dgHilitedLines of me
put the dgDataOfLine[it] of me into tData1 --no problem, array shows up as normal
get the dgHilitedIndexes of me
put the dgDataOfIndexes[it] of me into tData2 
--should be the same data as tData1 but in fact it is empty
...should be the same data as tData1
CAN be the same as tData1, but not neccessarily!
In case e.g. you have sorted the DG then index <> line!

But you used a slightly wrong syntax, it should read:
put the dgDataOfINDEX[it]... (singular!)
That should do the trick.

Important hint:
Do not use IT unless really neccessary like in getting data from dialogs.
IT will change when you least exspect IT!
Use a variable, no extra cost really ;-)

Code: Select all

put the dgHilitedLines of me into tHLines
put the dgDataOfLine[tHLines]...
Best

Klaus

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Datagrid: Problems with dgdata?

Post by ittarter » Sun Aug 26, 2018 10:25 pm

Thanks for your comments, Klaus. I don't think you touched on the main issue yet. Any idea what could cause the behavior I listed in my original post? I think the problem with calling data from the index is due to some deeper problem, the same thing that's causing a ridiculous 30-second period of unresponsiveness and the total inability to sort. Any idea what that might be?
Klaus wrote:
Sun Aug 26, 2018 6:57 pm
But you used a slightly wrong syntax, it should read:
put the dgDataOfINDEX[it]... (singular!)
I have always used plural and it normally works! I follow http://lessons.livecode.com/m/datagrid/ ... a-grid-api but if singular is better for some secret reason I will certainly do it. I was under the impression that the plural was chosen in order to clearly support multiple highlights.
Do not use IT unless really neccessary like in getting data from dialogs.
IT will change when you least exspect IT!
Heh, I don't usually, for exactly that reason. I was using it here to give the simplest possible code for forum support.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid: Problems with dgdata?

Post by Klaus » Mon Aug 27, 2018 10:10 am

Hi ittarter,
ittarter wrote:
Sun Aug 26, 2018 10:25 pm
Thanks for your comments, Klaus. I don't think you touched on the main issue yet. Any idea what could cause the behavior I listed in my original post? I think the problem with calling data from the index is due to some deeper problem, the same thing that's causing a ridiculous 30-second period of unresponsiveness and the total inability to sort. Any idea what that might be?
at least I touched ONE issue! 8)

Please provide more infos:
What platform are you experiencing the delay?
In a standalone? In the IDE, too?
What version of LC are you using
ittarter wrote:
Sun Aug 26, 2018 10:25 pm
Klaus wrote:
Sun Aug 26, 2018 6:57 pm
But you used a slightly wrong syntax, it should read:
put the dgDataOfINDEX[it]... (singular!)
I have always used plural and it normally works! I follow http://lessons.livecode.com/m/datagrid/ ... a-grid-api but if singular is better for some secret reason I will certainly do it. I was under the impression that the plural was chosen in order to clearly support multiple highlights.
"singular" is not better, but simply correct.
"dgdataofindixes" is not listed in the API, and if you try to access a non-existent custom property, the engine usually returns EMPTY! Did yout try with the singular?
ittarter wrote:
Sun Aug 26, 2018 10:25 pm
Klaus wrote:
Sun Aug 26, 2018 6:57 pm
Do not use IT unless really neccessary like in getting data from dialogs.
IT will change when you least exspect IT.
Heh, I don't usually, for exactly that reason. I was using it here to give the simplest possible code for forum support.
I can only comment what I read here, not what you are usually doing at home. :D


Best

Klaus

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Datagrid: Problems with dgdata?

Post by ittarter » Mon Aug 27, 2018 2:11 pm

Klaus wrote:
Mon Aug 27, 2018 10:10 am
What platform are you experiencing the delay?
In a standalone? In the IDE, too?
What version of LC are you using
LC 9.0. Windows 10. The problems occur in both the IDE and Windows Standalone.
"singular" is not better, but simply correct.
Noted. I'll use it from now on. Yes, I can now call an index the datagrid I am having trouble with. Thanks!

Sorting doesn't work. After attempting to sort, I can no longer highlight individual rows by clicking on them. (All visible rows display the blue-ish "highlighted" color). The rows do not change their order AT ALL and the array values

Code: Select all

dispatch "SortDataByKey" to me with "sequence", numeric, ascending --in the dg group script
I've tried different array keys, numeric vs text, descending vs ascending. No change.

Scrolling doesn't work. The vscrollbar appears disabled (washed out), which normally means that there are no more rows beyond what the datagrid is currently showing (which isn't true; there are 40+ array keys and only about half are visible).

The 30-second delay is not happening today.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid: Problems with dgdata?

Post by Klaus » Mon Aug 27, 2018 3:01 pm

Hm, never had any of these problems on my Mac...

You said you have all these scripts in the Datagrid itself (... to me...), how do you "trigger" them from "outside"?
Do you send something to your datagrid?

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Datagrid: Problems with dgdata?

Post by ittarter » Mon Aug 27, 2018 3:10 pm

To isolate the problem I use simple test buttons as well as the message box, but yeah, normally I would call a sort from the card script or possibly another object on the card.

As another example, if I use the message box to execute this:

Code: Select all

dispatch "RefreshList"to group "indicators"
then my datagrid rows can no longer be highlighted by clicking on them, even though the data hasn't changed. Everything is blue and unclickable until I recreate the array by setting the dgdata of the datagrid.

But even when I first set the dgdata to more lines than are visible, I won't get a functioning vscrollbar.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid: Problems with dgdata?

Post by Klaus » Mon Aug 27, 2018 3:13 pm

Hm, no brilliant ideas in the moment...

I could offer to take a look at your (stripped down) stack, if you like.
Send it to: klaus AT major-k.de and I will see if I can find anything.


Best

Klaus

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Datagrid: Problems with dgdata? [solved]

Post by ittarter » Tue Aug 28, 2018 6:03 pm

Thank you for looking at my stack, Klaus :)

For those who are curious, the problem was that the array I was using for dgdata had text, not numbers, for its keys, and I didn't know that datagrids can't work with text keys. But now I know! I don't think I would have figured that out by myself.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”