checkbox in a datagrid table autoupdate back to the array

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
whitebrick
Posts: 18
Joined: Wed Jul 02, 2014 12:36 pm

checkbox in a datagrid table autoupdate back to the array

Post by whitebrick » Wed Jul 02, 2014 1:03 pm

hello all,

I am hoping someone has advice on this as I've tried a few ways and not got it working but am sure there must be a way.

I am making an bespoke app for our small business invoicing needs. I originally had it in Excel

The end game for the project is to export it as an app - and for the app to be able to save data as we create new invoices. To this end I've created a substack with datagrid tables in it to store the necessary data. When new invoices get made the data can be appended to these data grids and saved within the app as they're in the substack.

In the main stack then I have a data grid table called payroll - this has the main header info for the invoice (job, client, total etc) but it also has checkboxes in each row for which jobs have been paid, need to be sent a reminder, 2nd reminder, wage paid and tax/super/gst set aside

When the mainstack loads it dumps the datagrid tables from substack into global arrays and then outputs the data for the 'payroll' array into a datagrid table in the main stack for viewing by the end user

Using the tutorials on the main site I managed to get checkboxes working for 'payment', 'reminder', 'reminder2', 'wage transferred' using TRUE/FALSE data to auto-populate the hilite status of each checkbox per row for each column. It looks great!

However if the end user clicks on the checkbox and changes the state from true/false (or any of the data in the datagrid table for that matter to be honest) I'd like to write that change back into the global array and switch a flag that the data has been changed so that if the end user tries to close the app it prompts to save the changes back to the substack

I've managed to capture the 'mouseup' event for the checkbox of each column and send a 'refresh_payroll_data' message down the line which I was catching on the card level with

Code: Select all

global invoice_header_data
global invoice_job_data
global payroll_data

on refresh_payroll_data
   --get the changes made to the display datagrid
   answer "made it to here"
   get the dgData of group "payroll_display" of this card
   put it into payroll_data
   set the dgData of group "payroll_data"  of card 1 of stack "ivm_database"  to payroll_data
end refresh_payroll_data
however it does not seem to be updating as I had anticipated. The data change doesn't make it back into the array

Can anyone offer me sagely advice or point me in the direction of the correct documentation??

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

Re: checkbox in a datagrid table autoupdate back to the arra

Post by Klaus » Wed Jul 02, 2014 1:41 pm

Hi Whitebrick,

1. welcome to the forum! :D

2. Why on earth does every beginner of Livecode start with teh most complex beast of Livecode objects EVER: the datagrid?
That was just a rhetorical question :D

OK, what you SEE in the datagrid group is just the visual representation of the actual data -> the dgdata of grp XYZ, which is an array.
So if you do not script that a click on a checkbox or whatever will update the data, nothing will happen to the data, as you have experienced.

Do you have a "mouseup" handler in your "Row behavior" which does this neccessary thing?


Best

Klaus

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: checkbox in a datagrid table autoupdate back to the arra

Post by bangkok » Wed Jul 02, 2014 4:28 pm

If you want to "catch" hilite not hilite of a checkbox within a datagrid.

-for each column that contains a checkbox, create a column behavior (button via properties)
-in this script, locate and modify (provided the checkbox name is "check")

Code: Select all

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
  
   if pData is "true" then 
      set the hilited of button "Check" of me to true
   else
      set the hilited of button "Check" of me to false
   end if
end FillInData
and

Code: Select all

on mouseUp pMouseBtnNum
    if pMouseBtnNum is 1 then
        ## did they click on the checkbox?
        if the short name of the target is "Check" then
            ## Update internal value in data grid
           SetDataOfLine the dgLine of me, "NameOfMyColumn", the hilite of the target      #### use the name of your column here
          ### and here you can add script to set for instance a global var, like a flag, so you know that the state has been changed
        end if
    end if
end mouseUp
Voilà.

So basically : when you click on the checkbox, its hilite state (true or false) is recorded into the array

When you display the content of the DG, if the column contains "true" then the checkbox is hilited (or not)

whitebrick
Posts: 18
Joined: Wed Jul 02, 2014 12:36 pm

Re: checkbox in a datagrid table autoupdate back to the arra

Post by whitebrick » Wed Jul 16, 2014 12:26 pm

thanks for these suggestions. Not new to hypertalk/rev media but this is my first datagrid effort

I had caught the FillInData pData handler and changed it as per the tutorial but I see the difference in your code is that "NameOfMyColumn" is where I went wrong :oops:


great stuff and thanks for such prompt replies - sorry I went off and did other projects for a bit.

have a great weekend

matthellstrom
Posts: 31
Joined: Mon Apr 27, 2015 3:09 pm

Re: checkbox in a datagrid table autoupdate back to the arra

Post by matthellstrom » Mon Jun 29, 2015 7:10 pm

Tagging along with this thread. I'm doing the same thing, but I'm using the dgh auto generated script. I try to put a custom function in the on mouseUp function to update my external data source, but it doesn't appear to ever get to that function. Is there something I'm missing? The contents of the dg get changed from false to true for that column, so I know that's happening, it just doesn't seem like the mouseUp handler ever fires.

Post Reply