Page 1 of 2

DataGrid Table with Customized Columns

Posted: Thu Apr 09, 2020 10:17 pm
by booee
I have a DataGrid Table, where I am customizing a column, so a cell can have more than one bit of data.
Image

You'll see in the NAME column I have another label field I called "bye".
I would like to populate the "bye" field with an array, however, I just cannot get it to work.

Here is the code of my BUTTON

Code: Select all

on mouseUp
   global BYEWEEKS
   
   put "ALABAMA" into theDataA[1]["Name"]
   put "AL" into theDataA[1]["Email"]
   put "ALASKA" into theDataA[2]["Name"]
   put "AK" into theDataA[2]["Email"]
     
   set the dgdata of group "DataGrid 1" to theDataA
   
end mouseUp
And then my Custom Column Behavior for column "Name":

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   
   put "4" into theDataB[1]["bye"]
   put "5" into theDataB[2]["bye"]
   
   -- Example:
   set the text of field 1 of me to pData
   --set the text of field 2 of me to theDataB
   set the text of field 2 of me to "bye"
end FillInData
You'll see the commented out "set the text of field 2 of me to theDataB", where I was trying to set an array to populate it, but that just turns it blank.

Any ideas at all on how to do this?

Re: DataGrid Table with Customized Columns

Posted: Thu Apr 09, 2020 10:24 pm
by Klaus
Hi booee,

we cannot display an ARRAY in a field, we need to "convert" it back to text to do so.


Best

Klaus

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 12:11 am
by booee
I was thinking that too, however, if I change the line of "on FillInData pData" to:
set the text of field 2 of me to pData
...it then populates the "BYES" with "Alabama" and "Alaska" respectively.
So it seems like it is then populating those fields with the array pData.

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 9:50 am
by Klaus
It only SEEMS! :D
When you have a customized column, FILLINDATA will only "pass" the content of one key of the initial array, so this works as intended.
This is different than the -> pData supplied to the whole datagrid wihtout customized columns!

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 3:07 pm
by booee
:) Lol...Well, that's a bummer. Thanks so much for letting me know. I appreciate you taking the time, so I didn't continue to kill another 2 days trying to find a workaround.

Do you know if there is any method to add unique information to a specific cell of a column.
For instance, can I have the "BYE" field in row 1 column 1 read "A" and the "BYE" field in row 2 column 1 read "B"?
And if this is possible, is there a method for this?

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 3:16 pm
by Klaus
Hm, good question... :D

I would probably do something like this with invisible columns and a clever naming scheme to access them like:
col1_vis <-> col1_invis

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 8:00 pm
by booee
Ohhh...Interestingly creative concept!

Do you know what/if the code function for copying a column of data to the fields would be? I'm at a total loss here (overwhelmed)? :)

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 8:15 pm
by Klaus
Not sure I understand, but a column is a column, be it visible or not. :D
Means everything in the array you provide will get into the datagrid.

And yes, datagrids are great, but unfortunately one of the most complex things to handle in LC!

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 8:46 pm
by booee
Oh, I was interpreting from you that there was some way to put the invisible columns data into the custom fields that I created in my column template.

Re: DataGrid Table with Customized Columns

Posted: Fri Apr 10, 2020 9:10 pm
by Klaus
Since I have no idea what exactly you are trying to do, why not create another INVISIBLE field(s) in that column?
Then you can fill them with whatever you want to, ecept arrays! :-)

Re: DataGrid Table with Customized Columns

Posted: Sat Apr 11, 2020 1:16 am
by booee
Sorry I'm not being super clear about that.
I'm trying to understand HOW to fill those fields for each individual row of the column. I'm not sure how to do that.

Re: DataGrid Table with Customized Columns

Posted: Sat Apr 11, 2020 9:09 am
by SparkOut
I'm completely flummoxed by what you are trying to present. What is it about the bye entry that needs such shenanigans? You could make it much easier by simply having another column between "name" and "email" and put the data there. Would users really mind separation of that data into a new column?
Or change to a "form" type datagrid and you will have control over the display however you want, although you will lose some of the tabular features. Sorting could be easy enough though.
I haven't played with customised columns before, but I will have a look later if I can. Not sure I will get to be able to give more advice than above though.

Re: DataGrid Table with Customized Columns

Posted: Sat Apr 11, 2020 9:11 am
by Klaus
You are probably thinking too complicated! :D
First create some more columns and set them to NOT visible in the inspector, then do like this:

Code: Select all

on mouseUp
   global BYEWEEK
   put "ALABAMA" into theDataA[1]["Name"]
   put "AL" into theDataA[1]["Email"]
   put "ALASKA" into theDataA[2]["Name"]
   put "AK" into theDataA[2]["Email"]
  ##
  put "4" into theDataA[1]["invisible_column_1"]
  put "5" into theDataA[1]["invisible_column_2"]
  put "4" into theDataA[2]["invisible_column_1"]
  put "5" into theDataA[2]["invisible_column_2"]
  ##   
   set the dgdata of group "DataGrid 1" to theDataA  
end mouseUp
BTW: With your initial way (one or two more fields per column) there is probably
no way to get this info back from the datagrid, since neither "the dgtext" nor "the dgdata"
of the datagrid contains these values!

Still no idea what you are trying to do with this?
Is this a secret? :shock:

Re: DataGrid Table with Customized Columns

Posted: Sat Apr 11, 2020 3:22 pm
by booee
Lol. No secret :) Just trying to figure out an ability for each cell to contain multiple pieces of information though, and not have all the information displayed across by column.

So if you see in my original image, the first cell has ALABAMA and BYE in the single cell.
What I need is a method to control the text of the word BYE in the cell.

By putting set the text of field 2 of me to "BYE" into the on FillInData pData
I could populate both cells 1 and 2 of column 1 to say the word "BYE" (or whatever text I put there). But it would put the word into both cells. I need to find a way to control what data gets put into each one (differently).

Re: DataGrid Table with Customized Columns

Posted: Sat Apr 11, 2020 3:52 pm
by Klaus
OK, but LCs datagrid library does not supply any API to what you intend!
So you need to do YOUR thing in the FILLINDATA handler.

Code: Select all

on FillInData pData

   ## pData is the content of the corresponding key of the array -> the dgdata
   set the text of field 1 of me to pData
   
   ## Your thingie here:
   set the text of field 2 of me to "Bye"
   set the text of field 3 of me to "Hello"
   ## etc...
end FillInData
And I already said so, there is no way to get these infos back easily!
Why on earth don't you use HIDDEN columns? Noone, except you, will tell the difference! :D
AND the datagrid API lets you fetch these infos easily!

However you could put more than ONE line into the ARRAY and "separate" them in your fillindata handler like this:

Code: Select all

on mouseUp
   global BYEWEEK
   put "ALABAMA" & CR & "Bye" & CR & "Hello" into theDataA[1]["Name"]
   put "AL" into theDataA[1]["Email"]
   # etc...
...

Code: Select all

on FillInData pData
  ## pData has MORE than one line so we do:
   set the text of field 1 of me to LINE 1 of pData
   set the text of field 2 of me to LINE 2 of pData
   set the text of field 3 of me to LINE 3 of pData
  ## etc...
end FillInData