Can't get data from a Data Grid

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

MichaelBluejay
Posts: 222
Joined: Thu Jul 01, 2010 11:50 am

Can't get data from a Data Grid

Post by MichaelBluejay » Fri Oct 04, 2019 5:40 pm

I have a data grid with a couple dozen rows of data. I'm pretty sure of this, because when I look at the data grid, I can see all the data. Also, put the dgNumberOfLines of grp ledger returns 24.

However, when I try to pull data out of the data grid, nothing appears in the message box: put the dgDataOfLine[5] of grp ledger

I tried this, but it didn't work any better: please put the dgDataOfLine[5] of grp ledger

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

Re: Can't get data from a Data Grid

Post by Klaus » Fri Oct 04, 2019 5:49 pm

Hi Michael,

neither a nice "Please" nor any bribe will help you here! :D

dgdataofline[linenumber] returns an ARRAY, which we cannot just put
anyhwere for display without processing, just like -> the dgdata of grp xyz!

If you need a one liner and do not want to parse the array, use -> the dgtext of grp XYZ
This will return CR & TAB delimited text, sou you could:

Code: Select all

...
## In your own interest get used to put QUOTES around object names!
## Or is -> ledger the name of a variable here?
put line 5 of the dgtext of grp "ledger"
...
Will show line 5 as TAB delimited text in the message box.

Best

Klaus

MichaelBluejay
Posts: 222
Joined: Thu Jul 01, 2010 11:50 am

Re: Can't get data from a Data Grid

Post by MichaelBluejay » Fri Oct 04, 2019 6:47 pm

Thank you, as usual.

Okay, so one solution is:

put the dgDataOfLine[5] of group "ledger" into theLine
put theLine[Column_Name_with_or_without_quotes_but_quotes_are_safer_so_it_doesnt_get_interpreted_as_a_variable]


But line 5 of the dgtext of grp "ledger" is nice and simple.

I agree with what others hav said in various other threads: Data Grid could be documented much better.

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

Re: Can't get data from a Data Grid

Post by Klaus » Fri Oct 04, 2019 7:04 pm

MichaelBluejay wrote:
Fri Oct 04, 2019 6:47 pm
put theLine["Column_Name_with_or_without_quotes_but_quotes_are_safer_so_it_doesnt_get_interpreted_as_a_variable"]
Good boy, although I prefer shorter column names! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Can't get data from a Data Grid

Post by bogs » Fri Oct 04, 2019 9:43 pm

Klaus wrote:
Fri Oct 04, 2019 5:49 pm
dgdataofline[linenumber] returns an ARRAY, which we cannot just put
anyhwere for display without processing...
While that is true, the processing isn't exactly all that monumental :D

It could be as simple as (depending on how much stuff your dealing with)

Code: Select all

	// ....previous code in handler
	put the dgDataOfLine[5] of grp ledger into tArray
	combine tArray using return	// or tab and return, or any other number of combinations...
	put tArray into field "ArrayData"
	/// ...whatever other code follows these gymnastics...
Image

MichaelBluejay
Posts: 222
Joined: Thu Jul 01, 2010 11:50 am

Re: Can't get data from a Data Grid

Post by MichaelBluejay » Sat Oct 05, 2019 9:53 am

I don't suppose there's a command to get all the data for a particular column (all the rows), as either a list or an array? I looked but couldn't find one.

I know I can do the dgtext of grp "nameOfTheDataGrid" to get the whole table of data and then loop through it, but the LiveCode company goes on and on about how LiveCode requires less code than other languages, so I'd like less code here, please.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Can't get data from a Data Grid

Post by bogs » Sat Oct 05, 2019 11:50 am

MichaelBluejay wrote:
Sat Oct 05, 2019 9:53 am
I looked but couldn't find one.
Hmmmmm.... you mean this? how-do-i-get-data-associated-with-a-row-or-column...

There is a lot of stuff about the dg right in the lessons under
LiveCode LessonsData GridLiveCode Data Grid
, and I believe most of that is now in the guide, which has a tab in the dictionary if your using Lc on Win or Mac, or can be opened in a pidf reader on 'nix.
Image
Image

MichaelBluejay
Posts: 222
Joined: Thu Jul 01, 2010 11:50 am

Re: Can't get data from a Data Grid

Post by MichaelBluejay » Sat Oct 05, 2019 1:46 pm

bogs wrote:Hmmmmm.... you mean this? how-do-i-get-data-associated-with-a-row-or-column...
Did you actually read the article, or just read the title and presume it answered my question? Because despite what the title of the article says, it does *not* actually show you how to get all data for a whole column in one fell swoop, at least not from my reading. This is a splendid example of how the LC documentation is ambiguous, incomplete, and typically raises more questions than it answers...especially where the Data Grid is concerned.

The Dictionary built into LC is so buggy it's practically useless. Usually searches return just the entry for $.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Can't get data from a Data Grid

Post by bogs » Sat Oct 05, 2019 2:03 pm

MichaelBluejay wrote:
Sat Oct 05, 2019 1:46 pm
Did you actually read the article, or just read the title and presume it answered my question?
If I (and I think most others) link it, most likely we also read it. In particular, I thought this section of it pertained to your question:
Getting Data In A Column Behavior wrote: Getting Data In A Column Behavior (Last section of the article)

If you want to get the data in a column behavior script you can use the dgIndex or dgLine and dgColumn custom properties of the column control. Here is an example that could be used in a Data Grid column behavior script:
Now the real question here is, did you just want to be snarky in your answer, or were you looking for actual feed back. I think I'll leave your threads to others who may actually put up with that kind of foolishness, have a nice day.
Image

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

Re: Can't get data from a Data Grid

Post by Klaus » Sat Oct 05, 2019 2:21 pm

Michael,

no idea why your tone suddenly unpleasantly changed? :shock:

We are only USERS of LC trying to help and Bogs just asked if you mean that lesson,
so your answer should have been a short Yes or No.

To answer your question, there is no shorter way to get the content of all column but a repeat loop like:

Code: Select all

...
put the dgData of grp "ledger" into tArray

## The keys are NOT neccessarily sorted, so we use this little trick:
put the num of lines of the keys of tArray into tMax
## We build an CR delimited list of all entries in your columns
repeat with i = 1 to tMax
  put tArray[i]["your column name here"] & CR after tColumns
end repeat
answer tColumns
...
If that is still too tedious for you, please complain at: support@livecode.com 8)

And presenting a shorter (than the above 5 lines) example in other languages would be very welcome. :D


Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can't get data from a Data Grid

Post by dunbarx » Sat Oct 05, 2019 5:37 pm

I will assume you are not being snarky.
The Dictionary built into LC is so buggy it's practically useless. Usually searches return just the entry for $.
It is not buggy, although it is slow. I never see a "$" in the filtered list unless I ask for it, which I never do. It can use improvement, like all dictionaries, and you are welcome to do so, since it is open to that sort of thing. But it is invaluable as a learning tool.

Someone please remind us both where the "alternate" dictionary is. I am not at my normal computer, and do not have the URL here. Anyway, that one is much faster.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9660
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Can't get data from a Data Grid

Post by dunbarx » Sat Oct 05, 2019 5:42 pm

On another note, though much powerful functionality is built into native DG commands and functions, I almost always extract the entirety of a DG "in the clear" using the DGText, and process in LC script. This way I do not need to keep the DG "language" in my head.

Just my comfort level. Then I simply restore the processed data back into the DG.

Craig

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

Re: Can't get data from a Data Grid

Post by Klaus » Sat Oct 05, 2019 5:45 pm

Hi Craig,

do you mean the "TinyDictionary" from Bernd and Mike?
Find it here: http://livecodeshare.runrev.com/stack/8 ... Dictionary


Best

Klaus

MichaelBluejay
Posts: 222
Joined: Thu Jul 01, 2010 11:50 am

Re: Can't get data from a Data Grid

Post by MichaelBluejay » Sat Oct 05, 2019 6:54 pm

dunbarx wrote:I will assume you are not being snarky.
I was being frustrated. When I'm pointed to an article as though it answers my question, when it doesn't in fact answer my question, then I'm afraid I can't see that as helpful.

About this:
LiveCode Lesson wrote:If you want to get the data in a column behavior script you can use the dgIndex or dgLine and dgColumn custom properties of the column control.
First, I don't "want to get the data in a column behavior script". I'm not using column behavior scripts. On the other hand, if the only way for me to get all the column data in one go were to use a column behavior script, then maybe I'd do so, but when reading that article, the question becomes, is it true that a column behavior script allow me to grab all the column data? The article didn't say (and neither did bogs).

Anyway, Klaus, first, thank you very much for confirming my suspicion that I'd have to traverse all the data rather than accessing the column data directly. Second, I agree that most other languages are more verbose than LC, but the fact that LC provides no direct way to access column data does seem very un-LC-like. We can target characters, words, items, and lines, and hundreds to thousands of properties, but when it comes to a column in a table, suddenly we have to roll our own, for some reason.

Finally, to answer your question about what languages let you get column data in fewer than five lines, here are two languages that do it in one:
R: df[, 1]

SQL: SELECT SUM(debitAmount) FROM journal;
LC is amazingly powerful and doesn't seem to have many shortcomings. The documentation is another matter, especially where the Data Grid is concerned.

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

Re: Can't get data from a Data Grid

Post by Klaus » Sat Oct 05, 2019 7:15 pm

Hi Michael,
MichaelBluejay wrote:
Sat Oct 05, 2019 6:54 pm
data in fewer than five lines, here are two languages that do it in one:
R: df[, 1]
SQL: SELECT SUM(debitAmount) FROM journal
ah, thank you!

You can add a feature request for this here: https://quality.livecode.com

Since the datagrid is written in LC, just like the whole IDE, you can also hack into the
datagridlibrary by yourself, if you like. Obviously this did not come up until today,
so this might be a good addition. :-)

In the meantime, if you need this functionality more often, just create a function from
my code snippet, pass the dgdata and the name of the desired column to it and let it
return the list of all column contents.


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”