loading data into DataGrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
loading data into DataGrid
I am accessing data - from a website and want to load it into a DataGrid. I have partially succeeded - my data is being loaded into the Titles part of the DataGrid...
so, I need it to just put the titles there, and put the data below.
Here is the code I am using
on mouseUp
put URL "myurl" into tFileContents
put line 1 of tFileContents into tColumnTitles
replace tab with return in tColumnTitles
set the dgProp[ "columns" ] of group "text" to tColumnTitles
set the dgText[true] of group "text" to tFileContents
end mouseUp
Here is an example of the fileContents (column titles and two lines)
Link_address topic
website address1 Custom market research services from Export.Gov
website address2 How to complete a NAFTA Certificate of Origin form
Thanks!
so, I need it to just put the titles there, and put the data below.
Here is the code I am using
on mouseUp
put URL "myurl" into tFileContents
put line 1 of tFileContents into tColumnTitles
replace tab with return in tColumnTitles
set the dgProp[ "columns" ] of group "text" to tColumnTitles
set the dgText[true] of group "text" to tFileContents
end mouseUp
Here is an example of the fileContents (column titles and two lines)
Link_address topic
website address1 Custom market research services from Export.Gov
website address2 How to complete a NAFTA Certificate of Origin form
Thanks!
Re: loading data into DataGrid
Good job getting the data off the web. As for putting it into a datagrid,
there's a lot of good code in this example stack. I think you'll find a of answers here.
CRUD SQLite example

there's a lot of good code in this example stack. I think you'll find a of answers here.
CRUD SQLite example
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: loading data into DataGrid
OK - I'm getting a lot closer. LiveCode has loaded the columns correctly, loaded information for the first column, but the second column is blank.
Here is my code: (I am bringing in an html file so I have to switch <br> with return and usetab with tab so that it can be read as tab delimited information). I used the code from LiveCode's How do I create a Datagrid dynamically from tab delimited data
on mouseUp
put url ("website address for my data") into theData
replace "<br>" with return in theData
replace "usetab" with tab in theData
lock screen --when doing visual stuff, this helps to speed things up
--make sure the group does not exist already
if there is a group "my Datagrid" then
delete group "my Datagrid"
end if
--copy the template group
copy group "DataGrid" of group "Templates" of stack "revDataGridLibrary" to this card
set the name of it to "my Datagrid"
set the dgProp["style"] of group "my Datagrid" to "table"
--position it nicely
set the rectangle of group "my Datagrid" to 0,the bottom of me + 16,the width of this card, the height of this card
--create row template
put the name of this stack into theMainstack
put "Data Grid Templates" && the seconds into theName
create invisible stack theName
set the mainStack of stack theName to theMainstack
go stack theName
create card
create field "label"
create graphic "Background"
group field 1 and graphic 1
set the name of last group to "Row Template"
go stack theMainstack
--point datagrid to template
set the dgProp["Row Template"] of group "my Datagrid" to the long id of group "Row Template" of stack theName
--create columns
put line 1 of theData into theColumns
--no empty column names are allowed, so I insert a space when that happens
replace tab & tab with tab & " " & tab in theColumns
replace tab with return in theColumns
set the dgProp["columns"] of group "my DataGrid" to theColumns
--add data
put true into firstLineAreNames
set the dgText[firstLineAreNames] of group "my DataGrid" to theData
end mouseUp
end mouseUp
Why won't my second column appear?
Here is sample data (columns link_address2 and topic) plus four data records after it.
Link_address2 usetab topic <br> http://build.export.gov/main/mrktresear ... etabCustom market research services from Export.Gov
<br> http://export.gov/logistics/eg_main_018131.aspusetabHow to complete a NAFTA Certificate of Origin form
<br> http://texastrade.org/training/online-i ... usetabWant to import? Global Sourcing Essentials
<br> http://www.sbdcglobal.com/about-sbdcglo ... bQualified trade leads in Mexico and Colombia through SBDCGlobal
Thanks
Here is my code: (I am bringing in an html file so I have to switch <br> with return and usetab with tab so that it can be read as tab delimited information). I used the code from LiveCode's How do I create a Datagrid dynamically from tab delimited data
on mouseUp
put url ("website address for my data") into theData
replace "<br>" with return in theData
replace "usetab" with tab in theData
lock screen --when doing visual stuff, this helps to speed things up
--make sure the group does not exist already
if there is a group "my Datagrid" then
delete group "my Datagrid"
end if
--copy the template group
copy group "DataGrid" of group "Templates" of stack "revDataGridLibrary" to this card
set the name of it to "my Datagrid"
set the dgProp["style"] of group "my Datagrid" to "table"
--position it nicely
set the rectangle of group "my Datagrid" to 0,the bottom of me + 16,the width of this card, the height of this card
--create row template
put the name of this stack into theMainstack
put "Data Grid Templates" && the seconds into theName
create invisible stack theName
set the mainStack of stack theName to theMainstack
go stack theName
create card
create field "label"
create graphic "Background"
group field 1 and graphic 1
set the name of last group to "Row Template"
go stack theMainstack
--point datagrid to template
set the dgProp["Row Template"] of group "my Datagrid" to the long id of group "Row Template" of stack theName
--create columns
put line 1 of theData into theColumns
--no empty column names are allowed, so I insert a space when that happens
replace tab & tab with tab & " " & tab in theColumns
replace tab with return in theColumns
set the dgProp["columns"] of group "my DataGrid" to theColumns
--add data
put true into firstLineAreNames
set the dgText[firstLineAreNames] of group "my DataGrid" to theData
end mouseUp
end mouseUp
Why won't my second column appear?
Here is sample data (columns link_address2 and topic) plus four data records after it.
Link_address2 usetab topic <br> http://build.export.gov/main/mrktresear ... etabCustom market research services from Export.Gov
<br> http://export.gov/logistics/eg_main_018131.aspusetabHow to complete a NAFTA Certificate of Origin form
<br> http://texastrade.org/training/online-i ... usetabWant to import? Global Sourcing Essentials
<br> http://www.sbdcglobal.com/about-sbdcglo ... bQualified trade leads in Mexico and Colombia through SBDCGlobal
Thanks
Re: loading data into DataGrid
Maybe I don't understand you corectly, but what do you expect in second column? There is no data for second column.
Marek.
Marek.
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: loading data into DataGrid
The second column is found after "usetab"
So - for this record
http://build.export.gov/main/mrktresear ... etabCustom market research services from Export.Gov
(this is truncating the middle part of the record - which is ...mrktresearch/eg_main_018208usetabCustom....)
I have LiveCode replace usetab with tab to create tab-delimited information.
so the second column is "Custom market research services from Export.Gov"
but only the http://build.export.gov/main/mkrtresear ... ain_018208 is showing up

So - for this record
http://build.export.gov/main/mrktresear ... etabCustom market research services from Export.Gov
(this is truncating the middle part of the record - which is ...mrktresearch/eg_main_018208usetabCustom....)
I have LiveCode replace usetab with tab to create tab-delimited information.
so the second column is "Custom market research services from Export.Gov"
but only the http://build.export.gov/main/mkrtresear ... ain_018208 is showing up

-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: loading data into DataGrid
I DID IT! I don't know why, but I changed the line:
put true into firstLineAreNames
and switched it to false
ALL THE DATA APPEARED! - including the first line that I had set up as titles. So, I manually named the columns and eliminated the titles in my data and it absolutely works.
I would be nice to know why Put true into FirstLineAreNames didn't work for me - but if I never know, the workaround will do it for me. Here is my final script:
on mouseUp
put url ("page_from_my_cold_fusion_website_with_data_only") into theData
replace "<br>" with return in theData
replace "usetab" with tab in theData
lock screen --when doing visual stuff, this helps to speed things up
--make sure the group does not exist already
if there is a group "my Datagrid" then
delete group "my Datagrid"
end if
--copy the template group
copy group "DataGrid" of group "Templates" of stack "revDataGridLibrary" to this card
set the name of it to "my Datagrid"
set the dgProp["style"] of group "my Datagrid" to "table"
--position it nicely
set the rectangle of group "my Datagrid" to 0,the bottom of me + 16,the width of this card, the height of this card
--create row template
put the name of this stack into theMainstack
put "Data Grid Templates" && the seconds into theName
create invisible stack theName
set the mainStack of stack theName to theMainstack
go stack theName
create card
create field "label"
create graphic "Background"
group field 1 and graphic 1
set the name of last group to "Row Template"
go stack theMainstack
--point datagrid to template
set the dgProp["Row Template"] of group "my Datagrid" to the long id of group "Row Template" of stack theName
--create columns
put "Link Address" & tab & "Topic" into tcolumntitle
put tcolumntitle into theColumns
--no empty column names are allowed, so I insert a space when that happens
replace tab & tab with tab & " " & tab in theColumns
replace tab with return in theColumns
set the dgProp["columns"] of group "my DataGrid" to theColumns
--add data
put false into firstLineAreNames
set the dgText[firstLineAreNames] of group "my DataGrid" to theData
end mouseUp
end mouseUp
Here is some data from the page:
(three lines - two columns usetab separates the columns)
http://build.export.govusetabCustom market research services
http://export.gov/usetabHow to complete a NAFTA Certificate of Origin form
http://texastrade.orgusetabWant to import? Global Sourcing Essentials
put true into firstLineAreNames
and switched it to false
ALL THE DATA APPEARED! - including the first line that I had set up as titles. So, I manually named the columns and eliminated the titles in my data and it absolutely works.
I would be nice to know why Put true into FirstLineAreNames didn't work for me - but if I never know, the workaround will do it for me. Here is my final script:
on mouseUp
put url ("page_from_my_cold_fusion_website_with_data_only") into theData
replace "<br>" with return in theData
replace "usetab" with tab in theData
lock screen --when doing visual stuff, this helps to speed things up
--make sure the group does not exist already
if there is a group "my Datagrid" then
delete group "my Datagrid"
end if
--copy the template group
copy group "DataGrid" of group "Templates" of stack "revDataGridLibrary" to this card
set the name of it to "my Datagrid"
set the dgProp["style"] of group "my Datagrid" to "table"
--position it nicely
set the rectangle of group "my Datagrid" to 0,the bottom of me + 16,the width of this card, the height of this card
--create row template
put the name of this stack into theMainstack
put "Data Grid Templates" && the seconds into theName
create invisible stack theName
set the mainStack of stack theName to theMainstack
go stack theName
create card
create field "label"
create graphic "Background"
group field 1 and graphic 1
set the name of last group to "Row Template"
go stack theMainstack
--point datagrid to template
set the dgProp["Row Template"] of group "my Datagrid" to the long id of group "Row Template" of stack theName
--create columns
put "Link Address" & tab & "Topic" into tcolumntitle
put tcolumntitle into theColumns
--no empty column names are allowed, so I insert a space when that happens
replace tab & tab with tab & " " & tab in theColumns
replace tab with return in theColumns
set the dgProp["columns"] of group "my DataGrid" to theColumns
--add data
put false into firstLineAreNames
set the dgText[firstLineAreNames] of group "my DataGrid" to theData
end mouseUp
end mouseUp
Here is some data from the page:
(three lines - two columns usetab separates the columns)
http://build.export.govusetabCustom market research services
http://export.gov/usetabHow to complete a NAFTA Certificate of Origin form
http://texastrade.orgusetabWant to import? Global Sourcing Essentials
Re: loading data into DataGrid
Hiy cusingerBUSCw5N,
check the last character of that "line", or maybe there is no "usetab" there? Or maybe other HTML "remnants"?
No idea without looking at the sourcetext.
Anyway:
...
set the dgText[TRUE] of group "my DataGrid" to theData
...
ususally works for me!
Best
Klaus
This sounds as if there is no CR/Return after your titles, means your line ONE is not a sepearate line somehow,cusingerBUSCw5N wrote:... I changed the line:
put true into firstLineAreNames
and switched it to false
ALL THE DATA APPEARED! - including the first line that I had set up as titles. So, I manually named the columns and eliminated the titles in my data and it absolutely works....
check the last character of that "line", or maybe there is no "usetab" there? Or maybe other HTML "remnants"?
No idea without looking at the sourcetext.
Anyway:
...
set the dgText[TRUE] of group "my DataGrid" to theData
...
ususally works for me!

Best
Klaus
Re: loading data into DataGrid
Another hint:
...
set the dgText[TRUE] of group "my DataGrid" to theData
...
will ONLY work if the number of TABS/items of the first line really fit exactly the number of items of the other lines!
Best
Klaus
...
set the dgText[TRUE] of group "my DataGrid" to theData
...
will ONLY work if the number of TABS/items of the first line really fit exactly the number of items of the other lines!
Best
Klaus
-
- Posts: 339
- Joined: Wed Jul 11, 2012 9:24 pm
Re: loading data into DataGrid
got it... problem was html remnants thanks!