Problem when populate dataGrid Table by file

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

Post Reply
Eric Debrosse
Posts: 5
Joined: Sat Aug 01, 2009 9:44 am

Problem when populate dataGrid Table by file

Post by Eric Debrosse » Tue Sep 08, 2009 10:34 am

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

shadowslash
Posts: 344
Joined: Tue Feb 24, 2009 6:14 pm
Contact:

Post by shadowslash » Tue Sep 08, 2009 12:23 pm

You might want to consider looking at the following link... It's gonna help you a bunch.

http://revolution.screenstepslive.com/s ... s/datagrid
Parañaque, Philippines
Image
Image

Eric Debrosse
Posts: 5
Joined: Sat Aug 01, 2009 9:44 am

Post by Eric Debrosse » Tue Sep 08, 2009 1:27 pm

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Tue Sep 08, 2009 1:49 pm

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

Eric Debrosse
Posts: 5
Joined: Sat Aug 01, 2009 9:44 am

Post by Eric Debrosse » Tue Sep 08, 2009 2:11 pm

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Tue Sep 08, 2009 2:28 pm

C'est merveilleux, Eric :)

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Tue Sep 08, 2009 4:02 pm

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.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

Post Reply