Page 1 of 1
DataGrid - Implement Event for a Single Column
Posted: Tue Sep 22, 2009 1:23 pm
by dickey
Hello all,
I have implemented a DataGrid which is functioning well.
I now wish to implement some events for an individual DataGrid column (most likely):
on returnInField
do something
end returnInField
or
on enterInField
do something
end enterInField
So I assume, via the 'Columns' Panel in the Inspector for the DataGrid, that I highlight the Column in question, then click the button Column Behavior, then add my events along with the build-in events listed like (dgDataControl, dgHilite, EditValue, FillInData, LayoutControl, mouseDoubleUp).
I tried this for Col 4, and tested something like:
on returnInField
ask "did the earth move for you?"
end returnInField
, however when I ran the program the event didn't fire.
Given that the keystokes available to the user to exit a DataGrid cell currently being edited are: Esc (exit no changes), Return and Enter (Commit Changes), I would have thought returnInField and/or enterInField were approriate events to use in this context. Perhaps I need to append my code to some pre-built event or handler?
Any assistance, greatly appreciated.
Kind regards, Andrew
Posted: Tue Sep 22, 2009 3:17 pm
by trevordevore
Hi Andrew,
If I understand correctly you have added returnInField to your custom column that you've defined. The 'returnInField' handler is in the behavior script for this custom column. If this is the case then 'returnInField' isn't a message that will be sent as the message only fires off when the user has an editable field open. Try using the 'returnKey' message instead and see if that works for you.
If you want to customize the script that runs while the field editor is open then that is different. Take a look at this lesson:
How Can I Customize The Field Editor Behavior?
DataGrid - Implement Event for a Single Column
Posted: Wed Sep 23, 2009 4:45 am
by dickey
Thanks Trevor,
I had read your article on custom field editor behaviors earlier in the day.
I have consumed most of the documentation which in my opinion is excellent.
I was thinking that my aim wasn't to create a custom column as such just append the returnInField handler code somewhere in the standard code already present. That did not work for me.
If I edit the script for the DataGrid itself (which is a blank canvas when first opened) and add my event handler there:
--example code
on returnInField
ask "do you love the DataGrid Control?"
end returnInField
the code does execute as expected on returnInField within any column being edited within the DataGrid. As a solution that approach works well and is perhaps another way of triggering scripts to every column, rather than changing columns definitions specifically.
Whilst my situation is different, I was imagining the classic invoicing grid, where a user edits the quantity, and several columns are re-calculated (like price, line total etc) as a result of that edit to a single column (in this case quantity).
(if you have time) What would you recommend as best practice in that scenario for triggering calculations with the DataGrid.
I could implement a handler for an indivudal column if I could identify the column/field currently being or last edited. Is there a way to do that?
I am already using the DataGrid API to access, various values eg:
put the dgDataOfIndex[pHilitedIndex] of me in theSelDataA
put theSelDataA["Col 4"] into field "head_up_display"
, so I am becoming familiar with the API. However can't spot how to identity the column/field currently being edited or last edited. I could then implement some conditional calculations, and some transaction logging (edit logging) where the sensitivity of the data might justify that level of attention.
Beside, doing some eval on Rev, off and on over the last few months - I have only spent the last three days in a concerted effort to port an application to Rev. I am really enjoying the process. I have been positively surprised by how easy the transition has been and the progress made to date, as well as the great support of the community on the forum.
Kind regards,
Andrew
Re: DataGrid - Implement Event for a Single Column
Posted: Wed Sep 23, 2009 4:57 am
by trevordevore
dickey wrote:I was thinking that my aim wasn't to create a custom column as such just append the returnInField handler code somewhere in the standard code already present. That did not work for me.
If you want to override the behavior for all columns in a data grid here is one approach:
How Do I Override the Default Behavior For Rendering Data to a Cell?
dickey wrote:If I edit the script for the DataGrid itself (which is a blank canvas when first opened) and add my event handler there:
--example code
on returnInField
ask "do you love the DataGrid Control?"
end returnInField
the code does execute as expected on returnInField within any column being edited within the DataGrid. As a solution that approach works well and is perhaps another way of triggering scripts to every column, rather than changing columns definitions specifically.
Since the Data Grid group script is in the message path of each column (each column is contained in the Data Grid group) this is another approach. returnInField is triggered if a field has focus. A column is just a field so if one of the column fields has focus then returnInField is sent. You may run into scenarios where returnKey is sent instead (i.e. focus is on a control in the data grid but not necessarily a field). I would process both messages.
dickey wrote:Whilst my situation is different, I was imagining the classic invoicing grid, where a user edits the quantity, and several columns are re-calculated (like price, line total etc) as a result of that edit to a single column (in this case quantity).
(if you have time) What would you recommend as best practice in that scenario for triggering calculations with the DataGrid.
I could implement a handler for an indivudal column if I could identify the column/field currently being or last edited. Is there a way to do that?
Take a look at this lesson:
How Can I Store An Option Menu Value When The User Makes a Selection?
The lesson shows how to use the dgColumn property in a column behavior script to get the column name. You can read up more on properties available to columns in this lesson:
Template Custom Properties & Messages
Let me know if that provides you the information you need to move on to the next step. If not I can provide more info.
dickey wrote:Beside, doing some eval on Rev, off and on over the last few months - I have only spent the last three days in a concerted effort to port an application to Rev. I am really enjoying the process. I have been positively surprised by how easy the transition has been and the progress made to date, as well as the great support of the community on the forum.
I'm glad to hear it is coming along nicely. Revolution is a great that keeps getting better and definitely has a great community.
DataGrid - Implement Event for a Single Column
Posted: Wed Sep 23, 2009 5:12 am
by dickey
Thanks Trevor,
Working my way through your response now. Thanks again.
- Andrew