Page 1 of 1
How to update a cell in a Data Grid table?
Posted: Wed Oct 16, 2019 4:18 pm
by MichaelBluejay
Is there a way to update just a single cell in a Data Grid table, without updating a whole row? The documentation is typically silent on whether it's possible to update the contents of just a single cell (or maybe it is documented, just very well hidden.) The best I can figure is that I have to update a whole row at a time.
Re: How to update a cell in a Data Grid table?
Posted: Wed Oct 16, 2019 4:22 pm
by Klaus
The datagrid API does not support this, so you will need to update the complete row.
Re: How to update a cell in a Data Grid table?
Posted: Wed Oct 16, 2019 9:05 pm
by dunbarx
I think of this differently.
I always extract the entirety of the DG with the dgText, do stuff in "ordinary" LC. and re-install. Thus I rarely distinguish between tasks involving one or more "cells", one or more rows or columns, or the whole shebang.
This is just laziness on my part. But my comfort zone is in LC, not in DG stuff. There is little penalty that I can see...
Surely if one is modifying the structure of the DG, then you need to do DG stuff. But if it just modifying text, I do it my way.
Craig
Re: How to update a cell in a Data Grid table?
Posted: Thu Oct 17, 2019 3:31 pm
by Zryip TheSlug
Hi Michael,
You can update the content of a cell by using the SetDataOfIndex or SetDataOfLine commands of the datagrid API.
Usage:
1. By using index reference
Code: Select all
SetDataOfIndex pIndex, pKey, pValue
where pIndex if the index of the line, pKey is the name of the column and pValue is the value to update
2. By using line reference
where pLine is the number of the row, pKey is the name of the column and pValue is the value to update
The usage context of SetDataOfIndex and SetDataOfLine is usually the datagrid group or row behavior, but you can use it from outside (a button outside the datagrid for example) by sending or dispatching the command to the datagrid group.
3. Example for updating the column "Product", row 3 with the new value "Product A" from a button outside the datagrid
Code: Select all
dispatch "SetDataOfLine" to grp "MyDataGrid" with 3, "Product", "Product A"
An important thing to know with the both commands SetDataOfIndex and SetDataOfLine is
you have to refresh the row once updated to have the value appear in the cell.
For doing that you have two commands: RefreshIndex (use it in conjonction with SetDataOfIndex ) or RefreshLine (use it in conjonction with SetDataOfLine)
So if we keep our example, the final code to use is:
Code: Select all
dispatch "SetDataOfLine" to group "MyDataGrid" with 3, "Product", "Product A"
dispatch "RefreshLine" to group "MyDataGrid" with 3
Have a look to this lesson for more informations and a full example:
http://lessons.livecode.com/m/datagrid/ ... a-in-a-row
And to the datagrid API where SetDataOfLine, RefreshLine, SetDataOfIndex, RefreshIndex are described:
http://lessons.livecode.com/m/datagrid/ ... a-grid-api
Re: How to update a cell in a Data Grid table?
Posted: Thu Oct 17, 2019 3:50 pm
by Klaus
Oh, the datagrid never ceases to surprise me, did not know this!
Sorry for my false posting, Michael!
Re: How to update a cell in a Data Grid table?
Posted: Fri Oct 25, 2019 10:49 pm
by MichaelBluejay
Thank you Zryip TheSlug, that's exactly what I needed.