DataGrid help needed.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
DataGrid help needed.
Hi,
I'm making a DG for products, of various types.
One particular type is a manufactured-in-house product.
This product consists of component type products that are already listed; the component products may be sized to spec, for example the manufactured product includes 2 (say) lengths of timber, cut from a longer purchased piece of timber.
I want to change the code of the component product to become the code of the manufactured product & the code of the component product.
This will ensure that a list of the sized component products will appear directly under the manufactured product when the DG is sorted.
It seems to me that the script required is to copy the component product row, then pasted as a new row, then code-edited. The user can then edit the size (and hence the product cost, which will be totalled with other sized component costs to become the cost of the manufactured product). I'm stuck on how to script to copy a row (where the user has been instructed to place the cursor), then paste it back in as a new row.
Any ideas ?
I'm making a DG for products, of various types.
One particular type is a manufactured-in-house product.
This product consists of component type products that are already listed; the component products may be sized to spec, for example the manufactured product includes 2 (say) lengths of timber, cut from a longer purchased piece of timber.
I want to change the code of the component product to become the code of the manufactured product & the code of the component product.
This will ensure that a list of the sized component products will appear directly under the manufactured product when the DG is sorted.
It seems to me that the script required is to copy the component product row, then pasted as a new row, then code-edited. The user can then edit the size (and hence the product cost, which will be totalled with other sized component costs to become the cost of the manufactured product). I'm stuck on how to script to copy a row (where the user has been instructed to place the cursor), then paste it back in as a new row.
Any ideas ?
Re: DataGrid help needed.
Hi CAsba,
if you mean that the user had selected/hilited the row in question with this:
If that is what you are after.
Best
Klaus
if you mean that the user had selected/hilited the row in question with this:
then you can:(where the user has been instructed to place the cursor)
Code: Select all
...
## Get the complete data array:
put the dgData of grp "you dg here..." into tArray
## Get the selected/hilited row:
put the dgHilitedIndex of grp "your dg here..." into tIndex
## Add the copy at the bottom of the datagrid:
dispatch "addData" to grp "your dg here..." with tArray[tIndex]
...
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9733
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: DataGrid help needed.
I use dataGrids now and then, and invariably do all processing "outside".
AS Klaus mentioned, you can extract the entirety of the contents of the dataGrid with either the "dgData", which gives an array, or the 'dgText" which gives an ordinary variable. Foe example:
Once you have that, you can then write handlers to modify that variable as needed. Then just:
For simple changes, you can work directly inside the DG. But for big stuff, that is how I do it.
Craig
AS Klaus mentioned, you can extract the entirety of the contents of the dataGrid with either the "dgData", which gives an array, or the 'dgText" which gives an ordinary variable. Foe example:
Code: Select all
put the dgText of group "yourDataGrid" into temp
Code: Select all
set the dgText of group "yourDataGrid" to temp
Craig
Re: DataGrid help needed.
Many thanks. I'll give it a try..
Re: DataGrid help needed.
Easily done, but not sure how you plan to allow the change by the user. If done outside the popup, then when updating the cell is easy to do withCAsba wrote: ↑Fri Apr 07, 2023 12:49 pmHi,
I'm making a DG for products, of various types.
One particular type is a manufactured-in-house product.
This product consists of component type products that are already listed; the component products may be sized to spec, for example the manufactured product includes 2 (say) lengths of timber, cut from a longer purchased piece of timber.
I want to change the code of the component product to become the code of the manufactured product & the code of the component product.
This will ensure that a list of the sized component products will appear directly under the manufactured product when the DG is sorted.
It seems to me that the script required is to copy the component product row, then pasted as a new row, then code-edited. The user can then edit the size (and hence the product cost, which will be totalled with other sized component costs to become the cost of the manufactured product). I'm stuck on how to script to copy a row (where the user has been instructed to place the cursor), then paste it back in as a new row.
Any ideas ?
Code: Select all
dispatch "SetDataOfIndex" to group "DataGrid" with pIndex, pKey,pValue
Alternatively you can also enter code in the fillInData handler for the column behavior, so the it populates the cell with an appropriate value. Note that you can access the values in other columns so you adjust data in fillInData with
Code: Select all
getDataOfIndex(the dgIndex of me, "<column name>")
S.