Issue with DataGrid

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
dalkin
Posts: 147
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Issue with DataGrid

Post by dalkin » Thu Aug 19, 2021 5:34 am

Howdy. I'm embarking on my first foray into databases and I've run into a problem I can't seem to overcome. I'm scraping data from a Wordpress website. Dragging a datagrid from the toolset to the card defaults to 'table' and I can connect and download the data into the 2 columns I want .. so far so good but it's when I try and display the data as a form (to allow for text wrapping) that the trouble starts.

For a start, the script examples in the LC lesson refer to tFieldRect but the default code in the 'Edit Script' button that appears when changing the behaviour of the datagrid from 'table' to 'form' is 'theFieldRect' and I can't get any data to show (I'm scrupulously following the lesson here).
Screen Shot 2021-08-19 at 1.25.12 pm.jpg
It's also curious that when displaying the data in a table, I can assign columns to various data eg. post_title and post_content (from the Wordpress DB) but changing the datagrid's default display from 'table' to 'form' causes the data to disappear (where have the columns gone?) and no matter what I do, I can't get the form to re-populate with data. Any advice appreciated.
If you're skating on thin ice you might as well dance.

stam
Posts: 702
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Issue with DataGrid

Post by stam » Thu Aug 19, 2021 1:14 pm

Hi dalkin,
I suspect you're not entering/formatting the data correctly. As long as the data grid finds the data formatted in a way it can use this, it will show up.

At any point if data is not showing in a data grid, you should check a) the 'contents' in the property inspector and b) the dgCache in the 'custom' panel of the property inspector (in the drop down menu) - these show you want data has been assigned to the data grid, and your job is to make the data show up as expected.

You can just use tab-separated values if using a table, but that gets more difficult when using a form.

Code: Select all

set the dgText of group "datagrid" to tTSVtext
where tTSVtext is the tab-separated data.
Extra care needs to be taken if text in each column contains a return, as this will confuse matters as it will look like a new record rather than just some column text with a return in it - in these cases it's easier to replace the return with a character that will definitely not be in your data, eg "§" and then I would use the array method below, and when assigning the text to the array, convert the "§" back to a return.

When using a form, I find it easier to enter data as an array (actually i do this a lot with tables as well); then in the fillInData you can just refer to the keys of the array. The important thing to remember as well, is that with a form, the array needs to be numerically indexed.

For example:
if your data is in tab-separated data with columns: column1, column2, column3, then you can just assign this data to the dgText of a table as is and it will work.

In a form, i find it easier and more straightforward to assign this to the dgData of the grid (an array):

Code: Select all

set the dgData of group "datagrid" to tArray
where tArray has the form:
[1][column1][data1]
[1][column2][data2]
[1][column3][data3]
[2][column1][data4]
[2][column2][data5]
[2][column3][data6]
...
[n][column1][dataN]
[n][column2][dataN]
[n][column3][dataN]

In a form, you would then edit the row template, create fields (easiest to name them the same as the column, eg the row template in this case would contain either labels or fields called column1, column2, column 3.

Then in the fillInData handler in the behaviour script you would just add:

Code: Select all

set the text of field "column1" of me to pDataArray["column1"]
set the text of field "column2" of me to pDataArray["column2"]
set the text of field "column3" of me to pDataArray["column3"]
I hope this makes sense - it's certainly very easy once you get the hang of it...

dalkin
Posts: 147
Joined: Wed Jul 04, 2007 2:32 am
Location: Blackheath, Australia
Contact:

Re: Issue with DataGrid

Post by dalkin » Mon Aug 23, 2021 9:30 pm

Where are my manners? Thanks for your help stam.
If you're skating on thin ice you might as well dance.

Post Reply

Return to “Databases”