Resize text and column width of Datagrid (table)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Resize text and column width of Datagrid (table)
Hi,
I am very new to live code and am having trouble resizing the contents of my datagrid (table). I would like to set the text size and column widths of the datagrid based on the height/width of the stack.
I have been able to resize the dimensions of the datagrid and other objects on the card but can't work out how to resize the contents of the datagrid. I read in the livecode mailing list archives that this can be done by "resizing everything on the datagrid template and then resetting the datagrid".
Does anyone have a sample scripts or some further information/pointers in order to help get me started?
I am very new to live code and am having trouble resizing the contents of my datagrid (table). I would like to set the text size and column widths of the datagrid based on the height/width of the stack.
I have been able to resize the dimensions of the datagrid and other objects on the card but can't work out how to resize the contents of the datagrid. I read in the livecode mailing list archives that this can be done by "resizing everything on the datagrid template and then resetting the datagrid".
Does anyone have a sample scripts or some further information/pointers in order to help get me started?
Re: Resize text and column width of Datagrid (table)
The place to look to get the hang of the datagrid ins and out is these locations
http://lessons.runrev.com/m/datagrid
http://lessons.runrev.com/s/lessons/m/d ... properties -- look under column properties on this page, also look at the textsize property
http://lessons.runrev.com/s/lessons/m/d ... a-grid-api -- look at refreshlist on this page
http://lessons.runrev.com/s/lessons/m/d ... s-messages
http://lessons.runrev.com/m/datagrid_tips
http://lessons.runrev.com/m/datagrid
http://lessons.runrev.com/s/lessons/m/d ... properties -- look under column properties on this page, also look at the textsize property
http://lessons.runrev.com/s/lessons/m/d ... a-grid-api -- look at refreshlist on this page
http://lessons.runrev.com/s/lessons/m/d ... s-messages
http://lessons.runrev.com/m/datagrid_tips
Re: Resize text and column width of Datagrid (table)
Thanks sturgis. I did go through all of those links over the past few days and didn't have much success. I tried again this morning after receiving your reply and I am now able to modify the text size and column widths of the datagrid when the stack is resized. I do have one more question though... I am able to refer to a percentage of the stack height/width when setting the width/height of a field or button (for resizing) but when I set the dgColumnWidth I am not able to use a percentage of the stack width/height. I must enter pixels (integer) instead. I also have to enter an integer when setting the dgProps["text size]". This means that I need to write a section of code to resize for each different mobile screen size. Is this normal practise or am I missing something? I just wanted to check as I am very new to this 

Re: Resize text and column width of Datagrid (table)
I don't know how the underlying code of the datagrid is set up but it is very possible that it expects only pixel widths for things like dgColumnWidth
But thats a pretty easy fix. Since is based on size rather than pass it a percentage directly, instead pass it a calculation in parens. (round(the width of card "cardname" * .1))
So, if you want a width of 15% something like
set the dgColumnWidth["myColumnName"] of group "myDgGroup" to (round(the width of this card * .15)) should do the trick. (could use trunc instead)
But thats a pretty easy fix. Since is based on size rather than pass it a percentage directly, instead pass it a calculation in parens. (round(the width of card "cardname" * .1))
So, if you want a width of 15% something like
set the dgColumnWidth["myColumnName"] of group "myDgGroup" to (round(the width of this card * .15)) should do the trick. (could use trunc instead)
Re: Resize text and column width of Datagrid (table)
I did try using calculations first as most other objects on the card are resized based on a calculation. I am able to add a calculation for dgProp["text size"] successfully. When I attempt use a calculation with dgColumnWidth the code doesn't error when I apply it but the calculation has no effect on the object when I resize the stack. As soon as I change it to pixels to object resizes as intended.
This works:
This doesn't work:
I will have a look at using trunc. If I understand correctly trunc will resize the column width to the length of the text so as long as I am able to resize the datagrid text to the correct size then the column width will follow.
This works:
Code: Select all
set the dgProp["Row Height"] of group "Leaderboard1" to 75
set the dgProp["header text Size"] of group "Leaderboard1" to tTextHeight/2
set the dgProp["text Size"] of group "Leaderboard1" to tTextHeight/1.5
set the dgProp["header height"] of group "Leaderboard1" to 28
set the dgColumnWidth["dbName"] of group "Leaderboard1" to 195
This doesn't work:
Code: Select all
set the dgColumnWidth["dbName"] of group "Leaderboard1" to (round(the width of this card * .15))
Re: Resize text and column width of Datagrid (table)
Hmm. Just set up a datagrid to test and executed
set the dgColumnWidth["Col 1"] of group 1 to round(the width of this card * .25)
and its working for me. The trunc function just lops the decimal places off the number without rounding, so no the column width won't follow. I'm just curious to know why its working when you designate pixels directly but not with the calculation.
I know you've surely checked, but is it possible there was a typo or something in the code? (like dgColumnWith or the like) when you were trying to calc the column sizes? Setting a typo'd property will fail silently because it will actually set the property.
If you pre-calc the value and place the value into a variable, and then just use the variable to set the size does it work then, and not when you're forcing evaluation during the setting of the property?
Can you post a non-working example stack for me to look at?
set the dgColumnWidth["Col 1"] of group 1 to round(the width of this card * .25)
and its working for me. The trunc function just lops the decimal places off the number without rounding, so no the column width won't follow. I'm just curious to know why its working when you designate pixels directly but not with the calculation.
I know you've surely checked, but is it possible there was a typo or something in the code? (like dgColumnWith or the like) when you were trying to calc the column sizes? Setting a typo'd property will fail silently because it will actually set the property.
If you pre-calc the value and place the value into a variable, and then just use the variable to set the size does it work then, and not when you're forcing evaluation during the setting of the property?
Can you post a non-working example stack for me to look at?
Re: Resize text and column width of Datagrid (table)
I tested again based on your most recent comments
This doesn't work:
This works:
It seems the issue was caused by the double use of the brackets. I removed the first set of brackets and the issue is resolved.
I also find that it will not work if I remove "round". When I remove "round" the calculation will work once and then when resizing a second and third time etc nothing on the card will resize at all. It seems to break all other resizing.
I can put a value for a width into a variable and use the variable instead of the calculation but again if I don't use "round" before the variable then all resizing for the card stops working.
Eg:
This works:
This doesn't work:
This doesn't work:
Code: Select all
set the dgColumnWidth["myColumnName"] of group "myDgGroup" to (round(the width of this card * .15))
This works:
Code: Select all
set the dgColumnWidth["myColumnName"] of group "myDgGroup" to round(the width of this card * .25)
I also find that it will not work if I remove "round". When I remove "round" the calculation will work once and then when resizing a second and third time etc nothing on the card will resize at all. It seems to break all other resizing.
I can put a value for a width into a variable and use the variable instead of the calculation but again if I don't use "round" before the variable then all resizing for the card stops working.
Eg:
This works:
Code: Select all
set the dgColumnWidth["dbName"] of group "Leaderboard1" to round(the width of this stack * .27)
OR
put (tStackHeight * .042) into tHeaderHeight
set the dgColumnWidth["dbName"] of group "Leaderboard1" to round(tHeaderHeight)
This doesn't work:
Code: Select all
set the dgColumnWidth["dbName"] of group "Leaderboard1" to (the width of this stack * .27)
OR
put (tStackHeight * .042) into tHeaderHeight
set the dgColumnWidth["dbName"] of group "Leaderboard1" to tHeaderHeight
Re: Resize text and column width of Datagrid (table)
Strange that it doesn't work with double parens, but i've seen stranger quirks in livecode. Glad you got it working.
Doesn't surprise me that skipping round causes issues since it will then try to size to a partial pixel, but would be nice if it failed a little more gracefully.
Sorry for steering you wrong with the doubled up paren example! I need to remember to test things before posting.
Doesn't surprise me that skipping round causes issues since it will then try to size to a partial pixel, but would be nice if it failed a little more gracefully.
Sorry for steering you wrong with the doubled up paren example! I need to remember to test things before posting.
Re: Resize text and column width of Datagrid (table)
No problems at all. I'm glad I have it all working and now it's something I just need to be mindful of in the future. Thanks so much for all of your help!!