Can't get data from a Data Grid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Can't get data from a Data Grid
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
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
Re: Can't get data from a Data Grid
Hi Michael,
neither a nice "Please" nor any bribe will help you here!
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:
Will show line 5 as TAB delimited text in the message box.
Best
Klaus
neither a nice "Please" nor any bribe will help you here!
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"
...
Best
Klaus
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Can't get data from a Data Grid
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.
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.
Re: Can't get data from a Data Grid
Good boy, although I prefer shorter column names!MichaelBluejay wrote: ↑Fri Oct 04, 2019 6:47 pmput theLine["Column_Name_with_or_without_quotes_but_quotes_are_safer_so_it_doesnt_get_interpreted_as_a_variable"]
Re: Can't get data from a Data Grid
While that is true, the processing isn't exactly all that monumental
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...
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Can't get data from a Data Grid
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.
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.
Re: Can't get data from a Data Grid
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.
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Can't get data from a Data Grid
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.bogs wrote:Hmmmmm.... you mean this? how-do-i-get-data-associated-with-a-row-or-column...
The Dictionary built into LC is so buggy it's practically useless. Usually searches return just the entry for $.
Re: Can't get data from a Data Grid
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:MichaelBluejay wrote: ↑Sat Oct 05, 2019 1:46 pmDid you actually read the article, or just read the title and presume it answered my question?
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.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:
Re: Can't get data from a Data Grid
Michael,
no idea why your tone suddenly unpleasantly changed?
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:
If that is still too tedious for you, please complain at: support@livecode.com
And presenting a shorter (than the above 5 lines) example in other languages would be very welcome.
Best
Klaus
no idea why your tone suddenly unpleasantly changed?
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
...
And presenting a shorter (than the above 5 lines) example in other languages would be very welcome.
Best
Klaus
-
- 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
I will assume you are not being snarky.
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
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.The Dictionary built into LC is so buggy it's practically useless. Usually searches return just the entry for $.
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
-
- 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
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
Just my comfort level. Then I simply restore the processed data back into the DG.
Craig
Re: Can't get data from a Data Grid
Hi Craig,
do you mean the "TinyDictionary" from Bernd and Mike?
Find it here: http://livecodeshare.runrev.com/stack/8 ... Dictionary
Best
Klaus
do you mean the "TinyDictionary" from Bernd and Mike?
Find it here: http://livecodeshare.runrev.com/stack/8 ... Dictionary
Best
Klaus
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Can't get data from a Data Grid
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.dunbarx wrote:I will assume you are not being snarky.
About this:
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).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.
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:
LC is amazingly powerful and doesn't seem to have many shortcomings. The documentation is another matter, especially where the Data Grid is concerned.R: df[, 1]
SQL: SELECT SUM(debitAmount) FROM journal;
Re: Can't get data from a Data Grid
Hi Michael,
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
ah, thank you!MichaelBluejay wrote: ↑Sat Oct 05, 2019 6:54 pmdata in fewer than five lines, here are two languages that do it in one:
R: df[, 1]
SQL: SELECT SUM(debitAmount) FROM journal
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