Resize text and column width of Datagrid (table)

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
amandab
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 15, 2013 10:12 pm
Contact:

Resize text and column width of Datagrid (table)

Post by amandab » Wed Mar 27, 2013 5:18 am

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?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Resize text and column width of Datagrid (table)

Post by sturgis » Wed Mar 27, 2013 2:27 pm

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

amandab
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 15, 2013 10:12 pm
Contact:

Re: Resize text and column width of Datagrid (table)

Post by amandab » Thu Mar 28, 2013 6:53 am

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 :)

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Resize text and column width of Datagrid (table)

Post by sturgis » Thu Mar 28, 2013 3:17 pm

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)

amandab
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 15, 2013 10:12 pm
Contact:

Re: Resize text and column width of Datagrid (table)

Post by amandab » Tue Apr 02, 2013 12:50 am

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:

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))
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.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Resize text and column width of Datagrid (table)

Post by sturgis » Tue Apr 02, 2013 1:12 am

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?

amandab
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 15, 2013 10:12 pm
Contact:

Re: Resize text and column width of Datagrid (table)

Post by amandab » Tue Apr 02, 2013 3:18 am

I tested again based on your most recent comments

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)
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:

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Resize text and column width of Datagrid (table)

Post by sturgis » Tue Apr 02, 2013 4:09 am

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.

amandab
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5
Joined: Fri Mar 15, 2013 10:12 pm
Contact:

Re: Resize text and column width of Datagrid (table)

Post by amandab » Tue Apr 02, 2013 4:59 am

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!!

Post Reply