Set all columns in a datagrid to "visible"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Set all columns in a datagrid to "visible"
Hi, how can I script to make all the columns in a datagrid table visible ? I've read the lessons, but I'm sorry to say I'm afraid it makes no sense to me.
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
CAsba.
There is a property, the "dgColumnIsVisible[yourColumnHere]" that can be set to "true"
I do not know if there is a blanket property, but you can always loop through all columns.
Craig
There is a property, the "dgColumnIsVisible[yourColumnHere]" that can be set to "true"
I do not know if there is a blanket property, but you can always loop through all columns.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
CAsba
Know that columns in a dataGrid are default named "Col 1, Col 2, Col 3,..."
Craig
Know that columns in a dataGrid are default named "Col 1, Col 2, Col 3,..."
Craig
Last edited by dunbarx on Wed Jun 28, 2023 8:39 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
All.
I never used that property, so decided to try it out. I made a new plain vanilla DG with a few columns and rows. But when I
Invoking the first line I get empty.
Invoking the second line does nothing.
???
MAC OS 13.4 LC 9.6.9
Craig
I never used that property, so decided to try it out. I made a new plain vanilla DG with a few columns and rows. But when I
Code: Select all
answer the dgColumnIsVisible["Col2"] of grp 1
set the dgColumnIsVisible["Col2"] of grp 1 to "false"
Invoking the second line does nothing.
???
MAC OS 13.4 LC 9.6.9
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
Here is another wrinkle that I do not understand. In a new DG with data in a few columns and rows, If I:
After line 1 I get the contents of the DG.
After line 2, which references a non-existent column, I get empty instead of an error.
I do not understand DG's.
Craig
Code: Select all
on mouseup
answer the dgText of grp 1
answer the dgColumnIsVisible["XXX"] of grp 1
end mouseup
After line 2, which references a non-existent column, I get empty instead of an error.
I do not understand DG's.
Craig
Re: Set all columns in a datagrid to "visible"
Hi CAsba,
do this:
Best
Klaus
do this:
Code: Select all
...
## Get a list of all columns in your DG
put the dgprops["columns"] of grp "your dg here..." into tColumns
## Now loop through this list and do the right thing with dgColumnisvisible:
repeat for each line tColumn in tColumns
set the dgColumnIsVisible[tColumn] of grp "your dg here..." to TRUE
end repeat
...
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
Klaus.
Sort of what I said.
But I could neither hide nor show a DG column with the test handler I published.
Craig
Sort of what I said.
![Wink :wink:](./images/smilies/icon_wink.gif)
But I could neither hide nor show a DG column with the test handler I published.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Set all columns in a datagrid to "visible"
Klaus.
AHA. There is a typo in the dictionary, which has as its example:
when even I know that the default column names are "Col 1, Col 2, etc". That is, a space between, say, "Col" and "2".
I just copied the example, and used it in more than one place.
But that is the easy part. Why then did LC not throw an error when I tried to manipulate column "Col1" (no space) which does not exist?
Craig
AHA. There is a typo in the dictionary, which has as its example:
Code: Select all
put the dgColumnIsVisible["col1"] of group "Data Grid"
I just copied the example, and used it in more than one place.
![Embarassed :oops:](./images/smilies/icon_redface.gif)
But that is the easy part. Why then did LC not throw an error when I tried to manipulate column "Col1" (no space) which does not exist?
Craig
Re: Set all columns in a datagrid to "visible"
what is already said is a good way.
Another way, especially if you have groups of columns you want to show/hide, is to simply set the dgProps["columns"] of the datagrid, where "columns" is a return-delimited list.
No matter what is in the dgData of the datagrid, it will only display the columns that are in dgProps["columns"]. If a column corresponds to a subway in dgData (as this is numerically indexed, all columns are subways to a numeric key), then it will be shown.
Just be aware that while the data will persist because it's in the dgData, the column widths may not do, so if not standard width you'd need to set that as well.
It's great for showing sets of columns with a single command...
Another way, especially if you have groups of columns you want to show/hide, is to simply set the dgProps["columns"] of the datagrid, where "columns" is a return-delimited list.
No matter what is in the dgData of the datagrid, it will only display the columns that are in dgProps["columns"]. If a column corresponds to a subway in dgData (as this is numerically indexed, all columns are subways to a numeric key), then it will be shown.
Just be aware that while the data will persist because it's in the dgData, the column widths may not do, so if not standard width you'd need to set that as well.
It's great for showing sets of columns with a single command...
Re: Set all columns in a datagrid to "visible"
Thanks everyone for all the info, and to you Klaus, for the definitive answer.
-
- VIP Livecode Opensource Backer
- Posts: 138
- Joined: Tue Feb 23, 2010 10:53 pm
- Location: Saint Louis, Missouri USA
Re: Set all columns in a datagrid to "visible"
I have a Data Grid with six columns. Investigating the properties of the Data Grid, I came across this:
According to the dictionary this allows all the columns to be set to visible at once. This is what the OP requested.
Beware: the dictionary says the command should be a line-delimited list of columns but I found that a comma-delimited list works.
You can use 'false' instead of 'true' anywhere in the command to selectively set the visibility of a column.
Try it, I think you will like it.
Bob
Code: Select all
on mouseUp pButtonNumber
set the dgProp["column visibility"] of group "Data Grid" to "true,true,true,true,true,true"
end mouseUp
Beware: the dictionary says the command should be a line-delimited list of columns but I found that a comma-delimited list works.
You can use 'false' instead of 'true' anywhere in the command to selectively set the visibility of a column.
Try it, I think you will like it.
Bob
Re: Set all columns in a datagrid to "visible"
Thanks BobCole, I'll take a look !