How to trigger an action *after* updating a data grid field?

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
stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

How to trigger an action *after* updating a data grid field?

Post by stam » Tue Dec 08, 2020 1:04 am

Hi all,
i want to run an action after updating a field in a data grid, that incorporates the updated values of the data grid.

As far as i can tell, the message to react to is CloseFieldEditor - but this runs before the value in the field editor has been added to the dgData, so

Code: Select all

on CloseFieldEditor
   //do some action with new text
end  CloseFieldEditor
runs the action with text that was there before the edit, not with the updated text.Is there a different message to trap that can do this?

I know i can probably get the text of the fieldEditor but that would be a lot of extra work - i just need to know when the update of the data grid's data has completed, but can't seem to find a message to do this...
Grateful for some pointers...

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: How to trigger an action *after* updating a data grid field?

Post by stam » Tue Dec 08, 2020 2:24 am

As a follow up to this, i can update the data grid manually and then call the action, but i wonder if there is a better way to do this.
Having seen related posts on this forum and stackoverflow, i've added this code to the CloseFieldEditor handler:

Code: Select all

On CloseFieldEditor pFieldEditor
   local tText, tColumn, tLineA
   put the text of pFieldEditor into tText
   put the dgColumn of the target into tColumn
   put the dgDataOfLine[the dgHilitedLine of me] of me into tLineA
   put tText into tLineA[tColumn]
   set the dgDataOfLine[the dgHilitedLine of me] of me to tLineA
   RefreshList 
   
   //do some action with new text --> now works with updated text
end CloseFieldEditor
What i was looking for was a way to trigger a command on the entire data grid after the update had finished, but couldn't find this - this is a solution that works, but seems rather wordy/kludgy.
Is there a better way?

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: How to trigger an action *after* updating a data grid field?

Post by SparkOut » Tue Dec 08, 2020 8:36 am

My first thought is to

Code: Select all

send "updaterCommand" in <some milliseconds>
but I don't know how many milliseconds to leave after the closeFieldEditor handler to ensure it is always acting on clean data. It should just queue up behind the dg updates just by being "sent" rather than interrupting, but I don't know what other sending the dg may be doing that may cause overlap.

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: How to trigger an action *after* updating a data grid field?

Post by stam » Tue Dec 08, 2020 1:33 pm

yeh i did try increasing intervals up to 250 ms but it didn't do the trick.

Code: Select all

send <command> in 250 milliseconds
was still processing the older data. I didn't try longer intervals and to be honest i wouldn't want to risk the data not being processed, so was hoping for some kind of handler i may have missed given how complex the data grid is.
As it is now, manually updating the dgData is quick enough and this works, it's just more code to maintain and duplicate to other similar instances...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: How to trigger an action *after* updating a data grid field?

Post by dunbarx » Tue Dec 08, 2020 3:58 pm

Hi.

I always send

Code: Select all

dispatch "refreshList" to group "myDataGrid"
whenever I, er, refresh my dataGrid. Couldn't you start your "action" right afterwards? Or do I misunderstand, and a line of code executed right after that command is executed "too soon", that is, you are really wanting a "dataGridFinallyRefreshed" message?

Trevor?

Craig

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: How to trigger an action *after* updating a data grid field?

Post by stam » Tue Dec 08, 2020 4:26 pm

HI Craig,

just to clarify this isn't a script-driven update (that would be easy); in this case, the user will double-click in a cell to edit a value.
After the dgData of the data grid has updated to contain the user's edits, i want to run a command.

Not sure how to trap the event other than what i've put in the code above, where i manually update the dgData so i know it's done, then run the command (which ends in a refreshList btw) - just wondering if there is a shortcut...

As you say, if there is some kind of dataGridFinallyRefreshed handler, that would be sweet.
Or if the approach i link to above is correct then at least i know and will apply this to all instances...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: How to trigger an action *after* updating a data grid field?

Post by dunbarx » Tue Dec 08, 2020 8:23 pm

Have you checked the message watcher while doing the double-click/data entry thing? Maybe something is in there...

Craig

Post Reply