sizing columns in a table field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Glenn Boyce
Posts: 137
Joined: Thu Jul 24, 2008 11:22 pm

sizing columns in a table field

Post by Glenn Boyce » Mon Aug 04, 2008 3:50 am

is there a wasy to size the columns. I see the height of each row can be changed but can't see how to alter column width.

Also I want the contents(multiple words) of a cell to be an item and to be able to load them into a global variable. At the moment I can only access bits of a line of the variable as words.

cheers

Glenn

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Aug 04, 2008 5:54 am

Hi Glenn,

To change the width of the columns, set the 'tabStops' property of the field. Pay attention to the format: it's a comma-delimited list of distances from the left side of the field, not individual column widths ; and the last widt is applied to all extra columns.
So a tabstops of "100,150,225" means that the first column is 100 pixels wide, the second is 50 pixels wide and all columns thereafter are 75 picels wide.

As for extracting the content of individual cells - here's some code.

Code: Select all

set the itemDelimiter to tab
put item 3 of line 1 of field "MyTableField" into tCellData
Revolution has no concept of cells per se, and you cannot have multiple lines of text in a cell - so the itemDelimiter is the way to go.

Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Tue Jan 05, 2010 6:36 pm

----- in english (or near english) -----

Hello,

as I met the same problem, I wrote a small tool to modify the width of a column very easily, and without being oblige to write a script or to do the calculation of the tabstops. The name of this tool is "Columna v1.0"

There are two ways to use this tool : as palette or as XCMD.

In the first case, it's enougth to write...

Code: Select all

go stack "Columna" as palette
In this window, you'll find some buttons on wich you could click to increase or decrease the width of a choosen column. This will work for table field even if the cell editing is set to true, even if the text is locked, etc.

Take a look at this page :

http://rg75.free.fr/hyperespace.columna.htm

In the second case, it's possible to modify the width of a column with a command integrated to Columna. This command - SetColWidth - comes with the following arguments : the name of the file where is the field to be modified, the name of the field to be modified, the number of the column in this field, and at least, the new size of the column

Code: Select all

setcolwidth "myFile" [name of the file/Text],"myField" [name of the field/Text],column number [integer],size of the column [integer]
Take careful to give the real name of the file and not the title of the window !!!

Here is an exemple of how to set the width of the column as near as possible to the length of the text in this column:

Code: Select all

on closefield
  put fld "Contact" into tempor
  set itemdelimiter to tab
  sort lines of tempor descending by the number of chars in item 1 of each --- max length in the choosen column
  put ((the number of chars in item 1 of line 1 of tempor)*9) into colwidth  ----*9 depend of course of the font's size
  start using stack "/folder1/folder2/Columna.rev"
  setcolwidth "Adresse","Contact",1,colwidth
  stop using stack "Columna"
end closefield
I hope it could be useful to some Revo users.

Renaud


--- En français ---

Bonjour,

comme je rencontrais le même problème, j'ai fini par créer un petit outil qui permet de modifier la largeur d'un colonne très aisément, et sans passer, ou presque, par la programmation et le calcul des tabstops. Il s'agit de "Columna v1.0".

Il est possible d'utiliser cet outil soit comme une palette, soit comme une XCMD

Dans le premier cas il suffira d'utiliser le script suivant :

Code: Select all

go stack "Columna" as palette
Dans cette fenêtre, ll y a des boutons sur lesquels il suffit d'appuyer pour modifier la largeur d'une colonne préalablement choisie. Cela marchera même s'il s'agit d'une table, même si le champ est verrouillé, et si l'option "cell éditing" est cochée.

Pour avoir un aperçu allez jeter un oeil à l'adresse suivante :

http://rg75.free.fr/hyperespace.columna.htm

Dans le second cas, il est possible de modifier la largeur d'une colonne à l'aide d'une commande intégrée à Columna. On utilisera en effet la commande SetColWidth avec les arguments suivants : le nom du fichier où se trouve le champ à modifier, le nom de ce champ, le numéro de la colonne dans le champs et enfin la largeur de colonne souhaitée.

Code: Select all

setcolwidth "myFile" [name of the file/Text],"myField" [name of the field/Text],column number [integer],size of the column [integer]
Prenez garde à bien indiquer le nom du fichier et non celui de la fenêtre !

Voici un exemple permettant de fixer la largeur d'une colonne en fonction de la longueur du teste qu'elle contient :

Code: Select all

on closefield
  put fld "Contact" into tempor
  set itemdelimiter to tab
  sort lines of tempor descending by the number of chars in item 1 of each ... max length in the choosen column
  put ((the number of chars in item 1 of line 1 of tempor)*9) into colwidth  ----*9 depend of the size of the font
  start using stack "/folder1/folder2/Columna.rev"
  setcolwidth "Adresse","Contact",1,colwidth
  stop using stack "Columna"
end closefield
Avec l'espoir que cela puisse être utile à quelques utilisateurs de Revo

Renaud

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Wed Jan 06, 2010 12:42 am

Hi Renaud,

thanks for posting your columna 1.0.
When choosing column 1 in a tablefield and pushing the 'smaller' button long enough for the width to go to 0 or below I get an error. Since the palette is password protected I dont know what is going on.
Also, when pushing the smaller button in a column greater 1 and going below 0 funny things happen to the width of the following columns.
regards
Bernd

PS I just post some code to adjust the width of all the columns of a table field to the formatted width of the text in the columns, in case you want to incorporate it in your palette:
It assumes a table field of the name "tField", adjust to your needs.

Code: Select all

on mouseUp
   
   -- unselect a currently focused cell
   if the short name of  the focusedObject  contains "revcell" then select empty
   
   set the itemDelimiter to tab
   
   put field "tField" into tData
   
   put 0 into tItemCounter
   repeat for each line aLine in tData
      put the number of items of aLIne into tCount
      if tCount > tItemCounter then put tCount into tItemCounter 
   end repeat
   
   -- get the formattedwidth for each item and put it into a list of the widths
   repeat with i = 1 to the number of lines of field "tField"
      repeat with j = 1 to tItemCounter
         put the formattedWidth of item j of line i of field "tField" +10 into tFormatteWidthOfItem -- 10 are added for margin
         if tFormatteWidthOfItem > item j of tColumnWidth then put tFormatteWidthOfItem into item j of tColumnWidth
      end repeat
   end repeat
   
   -- adjust the min and max width of the list of widths here
   put 150 into tMaxWidth -- set maximum width here
   put 20 into tMinWidth -- set minimum width here
   repeat with k = 1 to tItemCounter
      put (min(tMaxWidth,max(item k of tColumnWidth,tMinWidth))) into item k of tColumnWidth
   end repeat
   
   -- make a list for the tabstops in the format of added widths
   put 0 into tPixelCounter
   repeat with m = 1 to the number of items of tColumnWidth
      put item m of tColumnWidth + tPixelCounter into item m of tNewTabStops
      add item m of tColumnWidth to tPixelCounter
   end repeat
   
   put tab & tMinWidth after tNewTabStops -- so the non-text containing cells to the right are at minimum width
   
   replace tab with "," in tNewTabStops -- make the items comma delimited
   set the tabStops of field "tField" to tNewTabStops
end mouseUp

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Wed Jan 06, 2010 1:26 am

Hi Bernd,

Thanks for your test of columna.

This is the error message :

Type Field: tabstops is not a positive integer
Object button id 1006
Line set the tabstops of fld lechamp of stack lefich to lescols

when lescols (variable that contains the tabstops) = "0,100,200,300,400,500,600,700,800,900,1000,1100,1200,1300"

Conclusion : Revo don't like the "0" as first number in the tabstops. The result is really funny...
Ok, I will add a check, something like

Code: Select all

if item 1 of lescols < 1 then .....
For the moment I suggest you to never use a column whom the width is < to "1" :-)

Thanks also for your code and thanks very much for "formattedwidth" that I did'nt knew.Very useful indeed.

I 'm OK to incorporate your code in a new button ("adjust all" ?) of version 1. 1 of columna and, with your permission, I will also incorporate your name...?


Best regards,

renaud

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Wed Jan 06, 2010 1:40 am

Hi Renaud,
glad you liked the code snippet, do whatever you like with it, no need to quote me.

Just out of curiosity, what does NoN' stand for, of course you answer this only if you want. From your website I see you are into Mathematics? (AlKwarizmi). Unfortunately I am only into algorithms (runrev) and not into algebra, both these word are, as I learned, derived from al-Khwārizmī.
regards
Bernd

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Wed Jan 06, 2010 2:20 am

Bernd

If I take your code...It's seems natural to me to include your name as one of the author !
In french we said : "rendez à César ce qui appartient à César" , maybe, in english : (Give to Caesar what's belongs to Caesar"

Sorry for the explanation of NoN' but it's top secret. It's near to NaN (not an number) and it's a good reason that I can give to you.
And sorry, I'm not in mathematics, but in archaeology (prehistory and use-wear analysis). And now, I stop to contaminate this forum with personnal considerations.

You are rigth : al-Khwārizmī is a persian mathematician (with a lot of other knowledges) the name of which is at the origin of the word "algorithm". The origin of the word algebre is in the title of his book "Al-jabr wa'l-muqabalah".

If you are not in algebra it seems evident that you are in algorithm.

Thanks again for your code et au plaisir de te relire.

renaud

PS : I'll send you a pre-version of Columna 1.1

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Thu Jan 07, 2010 7:15 pm

Renaud,
I've put up a very rough stack with some controls for the width of colums in a tablefield.
if you copy this into the message box in Rev and hit return it should show up:

Code: Select all

go url "http://www.berndniggemann.on-rev.com/tableField/columnsTest.rev"
it has a slider that lets you change the width of the columns
first: you can set the width of a column number you put into a field (similar to your palette)
then you can press the option / alt-key and the slider changes all the tabstops to the same width
third you press a number on the main keyboard before you click on the slider then the slider changes the width of column number (number pressed) You can change the number while still having the mouse down on the slider and the respective column is changed.
Then there is a button for setting the width of the columns to the formattedwidth of the text in the columns which you already know.
regards
Bernd

I don't know if you know the site of Eric Chatonet http://www.sosmartsoftware.com/?r=revol ... ciels&l=fr
he has many "didacticiels" in french and in english. Unfortunately Eric passed away last year. I very much appreciate his stacks.

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Sat Jan 09, 2010 12:02 am

Hello Bernd

I appreciate too, the Eric's work, and the stacks he produces with Jean-Paul Chicheret in a french magazine many years ago. Even if I did'nt knew him personally, I've been vey sad to learn his death.

Otherwise, I've tested your not also "very rough stack", and almost all is OK except two things :

• the combination between option / alt-key and the slider (sometimes, the script editor appears, because, of course, the push on a button + option + alt-key...),

• when I press a number on the main keyboard before to click on the slider or when I move the slider, the slider changes the width of column whom the number is writen in the field "fColumn" but not the column I indicate with the keyboard.

About the slider, it's a very elegant way to change the width of the column, but I prefer the buttons because (as you notice it :wink: ) there is no limit to the size (200 points in your exemple) that you can give to a column.

It will be a very good thing than RunRev implement the possibility to resize the width of columns as Excel do, with just a drag of the Vertical line. In the meantime, we could try to offer some solutions...

Regards,

renaud

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Sat Jan 09, 2010 1:23 am

Renaud,
I am sorry, the option/alt key was a way to say:
On a Mac option Key
On Windows Alt Key
Just one key not two, then moving the slider alters all the columns to the same size. No Number needed for this.

If you just press a number on the mainkeyboard and then click the slider (without any additional key) then you change the column=number

if you dont press any keys you change the column that is indicated in the field.
As this shows I did a bad job for the interface. Too many functions. But I just wanted to show variations for the slider.

Eric Chatonet published ListMagic shortly before his death. It is really what we are trying to do and a lot lot more. He made the most of fields in Rev and overcomes many of the shortcomings of Revs native field/table field. https://secure.runrev.com/products/rela ... listmagic/
He also has a trial version of it.

But for the occasional use of a table field I think your attempt to make the columns easily movable is very nice and useful.

I am looking forward for what you come up with.

regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Sat Jan 09, 2010 10:47 pm

Renaud,

I experimented a little more with the table field and setting the column width. I found a way to do it dircectly by clicking into the columns and holding down the option key.
edit:
I have uploaded a new version to RevOnline. Look for "OldTableFieldDragDividers", or search for Bernd
end edit
Was a nice little puzzle. Code is not optimized but works in my testing. If it works for you also I might post it to RevOnline.
Funny, no one loves the table field, but with your interest in it I liked the idea of playing around with it. And to be honest it has a lot of limitations, probably too many. But anyways.
regards
Bernd
Last edited by bn on Tue Feb 16, 2010 6:21 pm, edited 1 time in total.

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Sat Jan 09, 2010 11:44 pm

Bernd,

1) Thanks for the reference to MagicList. It's a very, very, nice program. The resizing of columns is exactly what we could expect from Runrev and the "field manager".


2) Bravo for TheOldTableField, it's a great step and it works fine in my computer (Mac os X, ppc G4, Media V 2.9). There is not more than : to do the same thing without clicking on option/alt key (that means to detect when the mouse is over a V grid), and setting the cursor to "31" (the double bar with the arrow on left and rigth). The hollidays are now finish, and it will be more dificult for me to produce something in the next times. But as soon as possible, I'll try to write a "excel like" column resizing. Maybe you'll be faster than me :?

In any case, as reading your scripts and mine, I notice that to program this movement which countered so simple and natural it's not so simple. As you said "was a nice little puzzle". So, are we always in the good forum ("getting started with..." ?)

Nice to read you again.

Regard,

renaud

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Mon Jan 11, 2010 1:20 am

Renaud,
OK, I tried your suggestion. Which is the obvious way to do it.
I uploaded a new version of a script for a table field which lets you change the width of the columns by hovering over the column dividers, the cursor changes than.

The table field does a lot of things behind your back and I am not shure if I caught all of them, so try before use, use at own risk. Please tell me if it works for you.
edit
I have uploaded a new version to RevOnline. Look for "OldTableFieldDragDividers", or search for Bernd
end edit
regards
Bernd
Last edited by bn on Tue Feb 16, 2010 6:22 pm, edited 1 time in total.

NoN'
Posts: 96
Joined: Thu Jul 03, 2008 9:56 pm
Contact:

Re: sizing columns in a table field

Post by NoN' » Mon Jan 11, 2010 11:29 pm

Bernd,

Felicitations !! You've got it !!

I've just made some tries, for the moment, but it seems to work perfectly and I can only encourage all the users interested in the possibility of easy modification of the width of columns to test your work.

Felicitation again

Renaud

PS ; don't forget to sleep sometimes... :wink:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: sizing columns in a table field

Post by bn » Tue Jan 12, 2010 12:07 am

Renaud,

merci bien. Thank you.
Actually it was your interest in the table field that got me started, and your suggestion to grab the dividers directly.

And I like to ride a dead horse -> the table field :)

regards
Bernd

Post Reply