Data Grid Concatenate Info from Columns in Table

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AZSun
Posts: 30
Joined: Tue Mar 20, 2012 10:44 pm

Data Grid Concatenate Info from Columns in Table

Post by AZSun » Sun Oct 01, 2017 6:36 pm

Hi,
I have been learning and working with LiveCode for a while now, but now I've started learning datagrids and am having trouble. I am trying to concatenate text from two columns in a datagrid table, not a form, and place it automatically in a third column. I have columns "NameFirst", "NameLast", and "NameCombined".

I've used this code elsewhere with a button. This works for renaming the buttons. But, I'm looking for the table to auto fill the text fields in the 3rd column without clicking anything.

Code: Select all

put the dgHilitedLines of group "DataGrid 1" into theLine
put the dgDataOfLine[theLine] of group "DataGrid 1" into theDataA
put theDataA["NameFirst"] && theDataA["NameLast"] into tNameCombinedLabel
set the label of target to tNameCombinedLabel
I know I can do the data combining/concatenation prior to placing it in the datagrid, and I might if it keeps driving me crazy. But, I'm trying to understand so I'm still plugging away at getting it to work.
I've tried various versions of the following in the fillInData pData edit area of the data grid. I placed a text field inside column 3 and called the field "NameCombined".

Code: Select all

set the text of field "NameCombined" of me to pData["NameFirst"] && pData["NameLast"]
I've downloaded the datagrid .pdf and have been reading it and worked some of the datagrid lessons on this topic, but the lessons seem to focus on how to do it for forms. I'm wondering as well if it is working but I'm not able to see it because I've forgotten something to make it render in the table. I do have DataGridHelper and used that for my button tests. Thanks for any thoughts or help,

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

Re: Data Grid Concatenate Info from Columns in Table

Post by Klaus » Sun Oct 01, 2017 8:25 pm

Hi AZSun,

I made little test with a fresh datagrid "dg1" with three columns a, b and c.
Filled the first two colums and run this script in a button:

Code: Select all

on mouseup
   put the dgHilitedLines of group "dg1" into theLine
   put the dgDataOfLine[theLine] of group "dg1" into theDataA
   put theDataA["a"] && theDataA["b"] into theDataA["c"]
   set the dgDataOfLine[theLine] of group "dg1" to theDataA
end mouseup
Et voila, you get the picture. :D

Best

Klaus

AZSun
Posts: 30
Joined: Tue Mar 20, 2012 10:44 pm

Re: Data Grid Concatenate Info from Columns in Table

Post by AZSun » Sun Oct 01, 2017 10:23 pm

Thanks, I tested your example and as expected it works, but it requires highlighting a line and clicking the button.
I see in your example how you insert the data from the grid-- do the work --and then load(set) the data with the new concatenated stuff into column 3.
I'm looking for an automatic way. I believe it is in editing the behavior script but I don't know if this is possible, since it appears row behavior button only lights up when the Form style of Datagirds are used--Not Tables.

In the tutorial http://lessons.livecode.com/m/datagrid/l/7305 in the middle they show how to concatenate first names and last names but it is a datagrid in the Form format.

Thanks,

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

Re: Data Grid Concatenate Info from Columns in Table

Post by Klaus » Tue Oct 03, 2017 2:24 pm

I am not sure if this ispossible at all, at least not very straightforward.

I would probably prepare the DATA itself to have a third column and then set
the dgtext or dgdata of your datagrid:

Code: Select all

...
set itemdel to TAB
repeat for each line tLine in your_tab_delimited_data_for_datagrid
    put tLine & TAB & item 1 of tLine && item2 of tLine & CR after new_data
end repeat
## Delete trailing CR
delete char -1 of new_data
set the dgtext of grp "your datagrid here" to new_data
...
May even be faster than any datagrid function.


Best

Klaus

Post Reply