Page 1 of 1

Problem when populate dataGrid Table by file

Posted: Tue Sep 08, 2009 10:34 am
by Eric Debrosse
hi,
I have a problem when i populate datagrid table. I can't provide the header.
my script:
on mouseUp
## populate datagrid TAble with file
answer file "Choissez le fichier"
put it into ttheFile
put true into tHeader

set the dgText [tHeader] of group "Datagrid 1" to URL ("File:" & tThefile)
end mouseUp

When i put true into tHeader datagrid is empty
When is false , the dataGrid is fill, header are named "col1", "col 2"...

What wrong?

Thanks for help

I hope you could understand my english...

Posted: Tue Sep 08, 2009 12:23 pm
by shadowslash
You might want to consider looking at the following link... It's gonna help you a bunch.

http://revolution.screenstepslive.com/s ... s/datagrid

Posted: Tue Sep 08, 2009 1:27 pm
by Eric Debrosse
Thank you for your reply,
i read this article but the trouble is always. I try to populate datagrid table with an other file , nothing change.

I don't see where is my error

Posted: Tue Sep 08, 2009 1:49 pm
by Klaus
Bonjour Eric,

the problem is this:
When using
...
set the dgText of group "Datagrid 1" to tTabText
...
The "DataGrid" will create all necessary columms to display the tab delimited text in "tTabText".

When using:
...
set the dgText[TRUE] of group "Datagrid 1" to tTabText
...
it does NOT!

Is a bit strange and illogical, but that's the way it works right now.
Maybe Trevor will change/fix this in future versions of the DataGrid.

A workaround is to set the "column labels" separately:

Code: Select all

on mouseUp 
   answer file "Choissez le fichier" 
   put URL("file:" & it) into ttheFile 

   ## Now we "split" the content of the file
   put line 1 of ttheFile into tLabels
   delete line 1 of ttheFile 

   ## Set the text:
   set the dgText of group "Datagrid 1" to ttheFile

   ## Now we set the LABELS separately, but this needs to be a CR separated list:
   replace TAB with CR in tLabels
   set the dgProp["column labels"] of grp "DataGrid 1" to tLables
end mouseUp 
Hope that helps.


Best from germany

Klaus

Posted: Tue Sep 08, 2009 2:11 pm
by Eric Debrosse
Guten tag Klaus,

Thank you very much for your help.

Now i have a nice header in my datagrid and i learned more about DataGrid

Warm regards

Posted: Tue Sep 08, 2009 2:28 pm
by Klaus
C'est merveilleux, Eric :)

Posted: Tue Sep 08, 2009 4:02 pm
by trevordevore
Klaus wrote: Is a bit strange and illogical, but that's the way it works right now.
Maybe Trevor will change/fix this in future versions of the DataGrid.
Using the dgText a developer has to have an easy way of determining what data in the text gets mapped to existing columns without the data grid automatically creating columns for every column in the text. At the same time the dgText should provide a way for the developer to instanatly see something tangible in a data grid.

The question you have to ask is what should happen if the data grid has columns defined but the developer passes in text with column names that don't exist? Does the data grid wipe out the existing columns or just add to the existing columns? Wiping out columns wipes out all the settings the developer has set for them. That isn't a good idea. Adding columns on means the developer must delete columns from text that should not be mapped to any column which requires extra processing of the text file. I'm not keen on that either.

In the end you must keep in mind that a data grid table is not a single object like a field. Columns are objects in and of themselves. If you want to create a column with a proper name for every column in your text on the fly then set the dgProps["columns"] property and then assign the dgText.

Now, if I had more than just custom props and handlers at my disposal then the API could be more robust:

## Assign text to existing columns
set the text of data grid "Data" to myText using included header

## Assign text to existing columns, adding columns if they don't exist
set the text of data grid "Data" to myText using included header and adding columns

## Assign text, replacing columns
set the text of data grid "Data" to myText using included header and replacing columns

It is difficult to mimick the above using custom props since you can only pass one parameter in:

set the dgText[PARAM] of group "DataGrid" to myText

I have played around with a syntax such as this to work around the limitation:

set the dgText["headers included:true;columns:replace"] of group "DataGrid" to myText

This isn't very rev-like either though.