Page 1 of 2
Common Datagrid Column Properties
Posted: Wed Feb 03, 2010 11:44 pm
by phaworth
Many of the columns I use in different datagrids share common formatting properties, eg currency, date, etc. So far I have created a column behaviour every time I use a column that needs formatting in some way, with the appropriate code to display a currency value, date, etc but I'd really like to find a way to not have to keep repeating the code.
I already have code that translates between my database storage formats and display formats when the data goes into fields or buttons or any other objects. I guess I'm looking for a way to be to have that code be invoked every time data is loaded into a datagrid without having to keep repeating the code.
Any ideas?
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Fri Feb 05, 2010 3:43 pm
by trevordevore
One approach would be to define a getProp handler in your Data Grid group script that returned the type for any column in the Data Grid.
Code: Select all
getProp uColumnType pColumn
switch pColumn
case "start date"
return "date"
...
default
return "text"
end switch
end uColumnType
Then you could create a generic "default column behavior" button script that used the uColumnType custom property. The FillInData handler might look something like this:
Code: Select all
on FillInData pData
set the text of me to FormatData(pData, the uColumnType[the dgColumn of me] of the dgControl of me
end FillInData
FormatData is just a generic function defined somewhere in the message hierarchy that formats the data based on the type.
Re: Common Datagrid Column Properties
Posted: Sat Feb 06, 2010 7:11 pm
by phaworth
Thanks Trevor. That's actually very close to how I deal with this situation when handling fields, buttons, etc on the form so I have handlers that do all that stuff already but wasn't sure how to integrate them with a datagrid.
The absolute ideal solution would be that the code you gave for the FillInData handler would be the default code you create when any datagrid is placed on a card so I wouldn't have to define a custom behaviour for every column in every datagrid. I have naming conventions for objects that determine what type of db data they refer to and the same principle could be used to name columns in a datagrid.
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Mon Feb 08, 2010 9:11 pm
by trevordevore
Pete,
You could update your revDataGridLibrary to have the code you need as the default. The default script for Data Grid forms is stored in a custom property:
Code: Select all
the uDefaultScript of button "Default Script" of stack "revDataGridLibrary"
The default script for Data Grid table columns is here:
Code: Select all
the uDefaultScript of button "Default Column Script" of stack "revDataGridLibrary"
Just update these custom props with the scripts you want to be the defaults. You would need to update the scripts whenever you download a new version of Rev.
If you don't want to go the above route you still don't need to set a custom behavior for each column. Just set the "default column behavior" property of the Data Grid to the button with the behavior script you want to use. The script will be used by default for all columns in your Data Grid.
Re: Common Datagrid Column Properties
Posted: Mon Feb 08, 2010 9:28 pm
by phaworth
Thanks Trevor, sounds like either of these solutions would work.
I'm inclined to use the second one, setting the "default column behavior" and I just found how to do that in the Datagrid manual.
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Tue Feb 09, 2010 12:30 am
by phaworth
Hi Trevor,
Got this working great for any new datagrids. Now I want to convert my existing datagrids to use my default column behaviour but the column behaviors still show my original code in there, not the default code. I assume that's because the default code is copied over when the column behavior is created?
I could go through and delete all my existing datagrids then recreate them from the default grid I've set up but there's several of them so I'm wondering if there's another way to do this?
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Tue Feb 09, 2010 4:39 pm
by trevordevore
In the current version of the Data Grid library a custom column will not have the "default column behavior" assigned to it. Basically the Data Grid assumes that if you created a custom column you are using a custom behavior. I'm going to modify the library so that custom column controls inherit the standard column behavior or the "default column behavior" (if set) if the custom column control has no behavior assigned to it.
Right now you have two options -
1) Assign the behavior property of your custom column control to the same button as the "default column behavior" property.
2) Update the Data Grid behavior script with the new code.
Code: Select all
edit script of btn "Data Grid" of stack "revDataGridLibrary"
Search for string:
Code: Select all
copy control theColumn of theTemplateGroup to group theColumn of group "dgList" of me
Replace with this code:
Code: Select all
copy control theColumn of theTemplateGroup to group theColumn of group "dgList" of me
## Use default behavior if control doesn't have one assigned.
if the behavior of it is empty then
if the dgProps["default column behavior"] of me is empty then
set the behavior of it to the long ID of button "Default Column" of theResourceStack
else
set the behavior of it to the dgProps["default column behavior"] of me
end if
end if
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 6:45 am
by phaworth
Thanks Trevor. I used the first of the two methods you suggested and it works just fine. But it would be nice if custom columns inherit the default column behavior as you are planning. How can I find out when that modification has been done?
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 10:22 am
by phaworth
Hi Trevor,
I'm now finding that I need logic that is specific to certain custom controls in the datagrid in addition to what I use in the default column behaviour.
For example, one column in one datagrid contains a checkbox button. The common logic deals with showing it as checkd or unchecked but in addition to that, I need to change the contents of other objects on the card depending on the hilite of the checkbox.
What's the best way to achieve that without compromising the common logic that is in my custom behaviour?
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 3:45 pm
by trevordevore
The modification has already been made and submitted for the next release of Revolution.
Regarding notifying controls when the hilite in the Data Grid changes - A simple way of doing this is dispatching a message when a certain event happens in your Data Grid. For example, if you want to notify your program when a control is clicked on you might dispatch "HiliteButtonClicked" whenever the user clicks on the button.
You can pass any parameters when dispatching the message. The nice thing about dispatch is no errors occur if the message isn't handled so you can add it to your custom behavior and not worry about handling the message everywhere.
Another approach is to use a broadcasting system that broadcasts specific messages to controls whenever the checkbox is clicked on or your underlying data structure is changed. That is a little more involved though.
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 6:05 pm
by phaworth
Thanks Trevor, the dispatch solution sounds like the way to go.
Pete
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 9:30 pm
by phaworth
Hi Trevor,
Well I guess I'm not quite there yet. I tried the dispatch command with no target and nothing happened. I'm sure that's because the dispatch command is coming from the datagrid template card and the object I want to send the dispatched event to is on the card that contains the datagrid so wouldn't be in the message path.
It sounds like I have include a target object with the dispatch command but I want to preserve the ability of my default column script to be used for any datagrids. I'm thinking of defining a custom property of the button in the datagrid column that will define the target object for the dispatch command. Does that sound like a reasonable solution?
Thanks,
Pete
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 9:39 pm
by trevordevore
If you are using "dispatch" in the behavior script then the command will come from inside your Data Grid when it is sent, not the template card. You don't need to add a target. Just try handling the message that is being dispatched in the Data Grid group script and see if it gets triggered.
Re: Common Datagrid Column Properties
Posted: Wed Feb 17, 2010 9:50 pm
by phaworth
That works perfectly Trevor, thank you.
Pete
Re: Common Datagrid Column Properties
Posted: Thu Feb 18, 2010 6:19 am
by phaworth
Well, The fun just keeps coming! The way I've set up my shared datagrid is that I have it on a card which holds a library of various objects that I use in my app. My datagrids have a number of custom properties so I've defined them on the library copy and just change their contents in the application version of the datagrid. The library datagrid is also set up to use my custom default behaviour script in a button on the library card so I don;t have to set that up for every new datagrid.
When I want to use a datagrid, I copy and paste it from the library card onto my app card. I just noticed that results in every datagrid pointing to the same template. All is working fine but that feels like it could cause problems. Is there a way I can force each pasted datagrid to create a new template? Or is there a better way to do this? For example, maybe I should set up a new datagrid from the Tools palette then have a simple script that sets up it's default behaviors and my custom properties
Thanks,
Pete