How to copy a column of data from a datagrid table.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How to copy a column of data from a datagrid table.
Hi,
How to copy a column of data from a datagrid table to another datagrid table ? Can't find anything in the lessons that deals with this.
This is the context, if it helps..
I have datagrid 2, that contains all data on products. From this datagrid table, I want to extract a few of its columns to put into another datagrid (table) stocktake. This table does not require all the data in datagrid 2.
Incidentally, the datagrid stocktake has columns for data that datagrid 2 does not have; the data for these columns are to be entered following a physical stocktaking, and this datagrid, stocktake, will be printed, to be used as a stocktaking check list.
I hope this explains what I am trying to achieve..
How to copy a column of data from a datagrid table to another datagrid table ? Can't find anything in the lessons that deals with this.
This is the context, if it helps..
I have datagrid 2, that contains all data on products. From this datagrid table, I want to extract a few of its columns to put into another datagrid (table) stocktake. This table does not require all the data in datagrid 2.
Incidentally, the datagrid stocktake has columns for data that datagrid 2 does not have; the data for these columns are to be entered following a physical stocktaking, and this datagrid, stocktake, will be printed, to be used as a stocktaking check list.
I hope this explains what I am trying to achieve..
Re: How to copy a column of data from a datagrid table.
Hi CAsba,
do you want to copy one column or all columns of datagrid 1?
And do you already know how to assign the copied column(s) to the correct indexes/lines of datagrid 2?
Best
Klaus
do you want to copy one column or all columns of datagrid 1?
And do you already know how to assign the copied column(s) to the correct indexes/lines of datagrid 2?
Best
Klaus
Re: How to copy a column of data from a datagrid table.
Hi Klaus,
Many thanks for your reply.
I want to copy 5 columns into the other DG. I thought I would script it to copy one column at a time.
Not too sure what you mean in your second question. I thought I would put the copied column into the DG by the 'enter data' method, but I haven't tried it yet, so no, I don't know how.. 'I will cross that bridge when I get to it' was my strategy (!)
Many thanks for your reply.
I want to copy 5 columns into the other DG. I thought I would script it to copy one column at a time.
Not too sure what you mean in your second question. I thought I would put the copied column into the DG by the 'enter data' method, but I haven't tried it yet, so no, I don't know how.. 'I will cross that bridge when I get to it' was my strategy (!)
Re: How to copy a column of data from a datagrid table.
Hi CAsba,
OK, basically you need to:
Best
Klaus
I thought you already have some data in datagrid 2 and need to assign the copied column data to the appropriate index/line.
OK, basically you need to:
Code: Select all
...
## Get the data from the wanted column from the first datagrid:
## You could also use -> put the dgDataOfLine[your LINE number here]...
put the dgDataOfIndex[your index number here] of grp "datagrid 1" into tDataArray
put tDataArray["name of your column here"] into tData2Bcopied
## Get the index/line you want to copy the data to:
put the dgDataOfIndex[your index number here] of grp "datagrid 2" into tDataArray2
## Write column data to this array:
put tData2Bcopied into tDataArray2["name of target column here"]
## Write array back to datagrid 2:
set the dgDataOfIndex[your index number here] of grp "datagrid 2" to tDataArray2
...
Klaus
Re: How to copy a column of data from a datagrid table.
Hi Klaus,
I tried it but without success.
Also, I'm not sure if I've got my problem across to you correctly.
I may be wrong, but I suspect that the code you gave me would transfer ONE line/column intersection to the second DG; I am trying to transfer the whole column, with lots of data in it, to the second DG.
Does this make sense ?
I tried it but without success.
Also, I'm not sure if I've got my problem across to you correctly.
I may be wrong, but I suspect that the code you gave me would transfer ONE line/column intersection to the second DG; I am trying to transfer the whole column, with lots of data in it, to the second DG.
Does this make sense ?
Re: How to copy a column of data from a datagrid table.
Hi CAsba,
yo, sounds like I misunderstood you.
OK, maybe this is better.
Since i don't know how you want to put the extracted columns into the other datagrid
I need more info about that. But maybe this already helps.
Best
Klaus
yo, sounds like I misunderstood you.
OK, maybe this is better.
Code: Select all
...
## Get the data array of datagrid 1 to work with:
put the dgdata of grp "datagrid 1" into tData
## Extract all wanted columns into another array
## How many lines?
put the num of keys of tData into tNumOfKeys
repeat with i = 1 to tNumOfKeys
## 1. put the extracted columns into an array:
put tData[i]["name of wanted colum"] into tColumnArray[i]["name of wanted colum"]
## 2. Alternatively, if you need a CR delimited text list?
## put tData[i]["name of wanted colum"] & CR after tListOfColumns
end repeat
## Get rid of trailing CR
## delete char -1 of tListOfColumns
...
I need more info about that. But maybe this already helps.
Best
Klaus
Re: How to copy a column of data from a datagrid table.
Thanks Klaus, I'll try that, it will have to be on Monday...
Re: How to copy a column of data from a datagrid table.
Hi Klaus,
I just tried it..Not working. It seems to be the first line, as I tried to put tdata into fld "dgdg" to see if anything was in tdata,
and nothing was put into the field.
I just tried it..Not working. It seems to be the first line, as I tried to put tdata into fld "dgdg" to see if anything was in tdata,
Code: Select all
put the dgdata of grp "datagrid 1" into tData
put tdata into fld "dgdg"
and nothing was put into the field.
Re: How to copy a column of data from a datagrid table.
I may have misunderstood, but if not, you want some columns in datagrid1 to show in datagrid2?CAsba wrote: ↑Fri Jun 02, 2023 10:13 amHi,
How to copy a column of data from a datagrid table to another datagrid table ? Can't find anything in the lessons that deals with this.
This is the context, if it helps..
I have datagrid 2, that contains all data on products. From this datagrid table, I want to extract a few of its columns to put into another datagrid (table) stocktake. This table does not require all the data in datagrid 2.
Incidentally, the datagrid stocktake has columns for data that datagrid 2 does not have; the data for these columns are to be entered following a physical stocktaking, and this datagrid, stocktake, will be printed, to be used as a stocktaking check list.
I hope this explains what I am trying to achieve..
You could go through a process which what is probably outlined above of creating a column of text or an array out of data you want to display?
But why do that at all?
I can't think of any reason why you can't just
Code: Select all
set the dgData of datagrid2 to the dgData of datagrid1
Re: How to copy a column of data from a datagrid table.
tData (the dgdata of grp xyz) is an ARRAY!CAsba wrote: ↑Sat Jun 03, 2023 8:38 pmHi Klaus,
I just tried it..Not working. It seems to be the first line, as I tried to put tdata into fld "dgdg" to see if anything was in tdata,Code: Select all
put the dgdata of grp "datagrid 1" into tData put tdata into fld "dgdg"
and nothing was put into the field.
If you want to see the data in a field use -> the dgText of grp xyz
Re: How to copy a column of data from a datagrid table.
If you're set on having 'pure' data so the datagrid2 only has the column data you specify (as opposed to all the data and just showing some, as I posted above), you could write a short function as below to create the array for dataGrid2.
In the code below, pSourceLongID is the long id of your source data grid that contains the superset of data and pColumnList is a list of the column names (not labels) you want to extract and display in datagrid2 (code not tested):
You would then set the dgData of datagrid 2 to the output of this function:
where datagrid1 is the source datagrid and "col1, col2,..., colN" are the column names you want to extract from datagrid 1 and display in datagrid 2.
However, I still think my previous suggestion of simply setting the dgData to the superset that is in datagrid1 but only displaying the columns you want in datagrid2 is more practical...
HTH
Stam
--------------
Edit: gave variables more meaningful names and corrected a minor error as I forget 'the keys' creates a return, rather than comma, delimited list...
In the code below, pSourceLongID is the long id of your source data grid that contains the superset of data and pColumnList is a list of the column names (not labels) you want to extract and display in datagrid2 (code not tested):
Code: Select all
function getSubArray pSourceLongID, pColumnList
local tSourceArray, x = 0, tKeys, tSubArray
put the dgData of pSourceLongID into tSourceArray
repeat for each element tSourceRow in tSourceArray
add 1 to x
put the keys of tSourceRow into tKeys
repeat for each line tKey in tKeys
if tKey is in pColumnList then
put tSourceRow[tkey] into tSubArray[x][tKey]
end if
end repeat
end repeat
return tSubArray
end getSubArray
Code: Select all
set the dgData of datagrid2 to getSubArray(the long id of datagrid1, "col1, col2, ..., colN")
However, I still think my previous suggestion of simply setting the dgData to the superset that is in datagrid1 but only displaying the columns you want in datagrid2 is more practical...
HTH
Stam
--------------
Edit: gave variables more meaningful names and corrected a minor error as I forget 'the keys' creates a return, rather than comma, delimited list...
Re: How to copy a column of data from a datagrid table.
Hi,
Your idea, Stam, of copying the whole data into a DG with only some columns showing seems a pretty good solution. Many thanks, I'll try it..
Your idea, Stam, of copying the whole data into a DG with only some columns showing seems a pretty good solution. Many thanks, I'll try it..
Re: How to copy a column of data from a datagrid table.
Hi Stam,
I tried it - it worked ! - many thanks.
I tried it - it worked ! - many thanks.
Re: How to copy a column of data from a datagrid table.
Glad it helped! Also note that you don’t even need two data grids.
If the data grid contains the superset array of data you can simply change the dgProps[“colunns”] to only show the columns you want, so you could sett up buttons or a switch widget to toggle between the two for example - but not sure what suits your app best…
If the data grid contains the superset array of data you can simply change the dgProps[“colunns”] to only show the columns you want, so you could sett up buttons or a switch widget to toggle between the two for example - but not sure what suits your app best…
Re: How to copy a column of data from a datagrid table.
CAsba,
as you may have noticed, you cannot put an ARRAY into a field, OK, you actually can, but it will not display anything.
If you want to see/visualize an ARRAY, you can use a "treeview" widget:
Best
Klaus
as you may have noticed, you cannot put an ARRAY into a field, OK, you actually can, but it will not display anything.
If you want to see/visualize an ARRAY, you can use a "treeview" widget:
Code: Select all
...
set the arraydata of widget "your treeview widget here" to the dgData of grp "your datagrid here"
...
Klaus