While that example is useful as a starting point, it suffers from the same bugs as the one I referenced on jessewarden.com. At least the itemRenderers do. Select a few checkbox and then sort one of the columns and you'll see the selections get messed up.
Ben --- In [email protected], "Mikhail Shevchuk" <[EMAIL PROTECTED]> wrote: > > Here is also a good sample with HeaderRenderer > http://www.iepl.net/DataGridItemRendererSample/DataGridItemRendererSample.html > > > 2007/3/27, ben.clinkinbeard <[EMAIL PROTECTED]>: > > > > Hey Alex, I haven't had time to create an example of the behavior I > > was talking about but I can show you the example that started me on > > the path to overriding .data. > > > > http://www.jessewarden.com/archives/2006/10/checkbox_item_r.html > > > > Hopefully work will calm down soon and I can try to reproduce some of > > the odd behavior I saw during some of my early experiments. Also, I > > think the approach I used in the post referenced earlier (binding the > > header renderer to a property held outside the datagrid/dataprovider) > > is a pretty simple way to ensure consistent behavior. > > > > Additionally, I would still love to get more info about the abundance > > of events that headerRenderers seem to receive/the reinitialization > > you mentioned if you or anyone else can provide it. > > > > Thanks, > > Ben > > > > --- In [email protected] <flexcomponents%40yahoogroups.com>, > > "Alex Harui" <aharui@> wrote: > > > > > > Did you solve this yet? > > > > > > HeaderRenderers are a bit trickier. Their .data is a DataGridColumn, > > > and existing controls like CheckBox are set up to be itemRenderers, but > > > not headerRenderers. > > > > > > However, I got one working. The key thing was to block the sort event. > > > Another note is that the headerRenderer may get killed off and > > > re-created so you may need to set its selected property on > > > initialization. > > > > > > I block the sort event like this: > > > > > > // constructor > > > > > > DataGrid(listData.owner).addEventListener(DataGridEvent.HEADER_RELEASE, > > > sortEventHandler); > > > > > > private function sortEventHandler(event:DataGridEvent):void > > > { > > > if (event.itemRenderer == this) > > > event.preventDefault(); > > > } > > > > > > > > > ________________________________ > > > > > > From: [email protected] <flexcomponents%40yahoogroups.com> > > > [mailto:[email protected]<flexcomponents%40yahoogroups.com>] > > On Behalf Of Douglas Knudsen > > > Sent: Saturday, March 24, 2007 12:14 PM > > > To: [email protected] <flexcomponents%40yahoogroups.com> > > > Subject: Re: [flexcomponents] Re: datagrid header with checkbox > > > > > > > > > > > > when creating a custom header renderer, what is in the data property? > > > Can things be added? how? > > > I tried using data.headerText but got nothing. > > > > > > Ben, thanks for your notes for sure. Creating a itemRender for a DG is > > > not so painful really. Creating the headerRenderer is where things > > > don't seem the same approach. > > > > > > DK > > > > > > > > > On 23 Mar 2007 20:54:08 -0700, ben.clinkinbeard > > > <ben.clinkinbeard@ <mailto:ben.clinkinbeard@> > wrote: > > > > > > > > > Hi Alex, > > > > > > Re-reading it now, I see that my sentence about the data setter > > > isn't > > > very clear. I suppose its not a case of 'must' or 'always', but > > > any > > > time I've created or seen renderers that use a control of some > > > sort to > > > represent a piece of data, overriding the data setter is > > > necessary to > > > ensure consistent results when scrolling. I was thinking mostly > > > of > > > CheckBox renderers in DataGrids since thats what I've > > > encountered most > > > often, but I would venture to guess that it holds true for other > > > controls like ComboBox, Label, etc in things like Lists as well > > > as > > > DataGrids. > > > > > > For whatever reason, the list-based controls don't seem to be > > > able to > > > re-apply proper values/states on the itemRenderers when the > > > scrolling > > > initiates the recycling of displayed items. That is, since it > > > reuses > > > the same graphical assets and simply swaps the data for each > > > item when > > > the list is scrolled, binding the control to a value isn't > > > enough to > > > keep checked items checked, and unchecked items unchecked. > > > > > > If I am just dense and have missed an easier way to do things I > > > would > > > certainly appreciate any advice you can provide. Also, if need > > > be I > > > can try to throw together a quick example to demonstrate the > > > erratic > > > behavior I described. > > > > > > Thanks, > > > Ben > > > > > > > > > > > > --- In [email protected] <flexcomponents%40yahoogroups.com> > > > <mailto:flexcomponents%40yahoogroups.com> , "Alex Harui" <aharui@> > > > wrote: > > > > > > > > Ben, I'm not aware of a rule that you must override the .data > > > setter. > > > > Can you explain further? > > > > > > > > > > > > > > > > -Alex > > > > > > > > > > > > > > > > ________________________________ > > > > > > > > From: [email protected]<flexcomponents%40yahoogroups.com> > > > <mailto:flexcomponents%40yahoogroups.com> > > > > [mailto:[email protected]<flexcomponents%40yahoogroups.com> > > > <mailto:flexcomponents%40yahoogroups.com> ] On Behalf Of > > > ben.clinkinbeard > > > > Sent: Friday, March 23, 2007 5:48 PM > > > > To: [email protected] <flexcomponents%40yahoogroups.com> > > > <mailto:flexcomponents%40yahoogroups.com> > > > > Subject: [flexcomponents] Re: datagrid header with checkbox > > > > > > > > > > > > > > > > Hi Douglas, > > > > > > > > If you look in the docs, you'll see that itemRenderers (and > > > > itemEditors) are the primary use cases for ClassFactory. In > > > fact, when > > > > you say something like <mx:List id="myList" > > > > itemRenderer="ProductRenderer">, the compiler actually creates > > > a > > > > ClassFactory instance for you behind the scenes. Explicitly > > > creating > > > > the ClassFactory instance simply allows you to use the > > > properties > > > > property, which is the key to making a reusable renderer. > > > Further > > > > evidence of the correlation is that the itemRenderer and > > > itemEditor > > > > properties are of type IFactory, which is what ClassFactory > > > implements. > > > > > > > > I don't want you to think I'm being defensive, its just that > > > > itemRenderers seem to be a topic that comes up repeatedly as a > > > pain > > > > point for developers. I think if people had a better > > > understanding of > > > > how they worked (especially the rule that you MUST override > > > the data > > > > setter method), people could avoid a lot of headaches. > > > > > > > > The post I wrote prior to the one Darron referenced actually > > > shows how > > > > to create a renderer in what I guess is the more traditional > > > method > > > > (itemRenderer="MyRendererClass"), so that may be of help to > > > you. > > > > However, the reason I initially began investigating > > > ClassFactory was > > > > because of problems I was having getting a CheckBox to > > > function as a > > > > headerRenderer. For reasons still unknown to me, > > > headerRenderers seem > > > > to fire events extremely frequently, which caused difficulty > > > getting > > > > it to respond to user interaction in a predictable way. > > > > > > > > Let me know if you have any other questions or concerns about > > > > renderers (and/or my approach to them) and I will do my best > > > to help. > > > > > > > > Thanks, > > > > Ben > > > > > > > > --- In [email protected]<flexcomponents%40yahoogroups.com> > > > <mailto:flexcomponents%40yahoogroups.com> > > > > > > > <mailto:flexcomponents%40yahoogroup s.com <http://s.com> > , > > > "Douglas Knudsen" > > > > > > > <douglasknudsen@> wrote: > > > > > > > > > > thanks, been reading that. Seems like this approach is way > > > off the > > > > > direction normally taken for renderers though, eh? Not to > > > knock Ben > > > > mind > > > > > you. Can add checkboxes to a datagrid cell with out that, > > > correct? > > > > So why > > > > > not headers? > > > > > > > > > > oh...answering my other question...headers are rendered by > > > > > DataGridItemRenderer by default according to the docs. > > > > > > > > > > DK > > > > > > > > > > On 23 Mar 2007 13:31:04 -0700, Darron J. Schall <darron@> > > > > > wrote: > > > > > > > > > > > > Check out > > > > > > > > > > > > > > > > > > > http://www.returnundefined.com/2006/11/creating-truly-reusable-renderers > > > <http://www.returnundefined.com/2006/11/creating-truly-reusable-renderer > > > s> > > > > -with-classfactory/ > > > > > > > <http://www.returnundefined.com/2006/11/creating-truly-reusable-renderer > > > <http://www.returnundefined.com/2006/11/creating-truly-reusable-renderer > > > > > > > > s-with-classfactory/> > > > > > > > > > > > > -d > > > > > > > > > > > > > > > > > > Douglas Knudsen wrote: > > > > > > > > > > > > > > How the heck to get a checkbox in the header of a data > > > grid, eh? > > > > Let > > > > > > > me re-phrase that some...a workable checkbox. I can > > > create a > > > > custom > > > > > > > renderer in AS to put one there, but can't click it at > > > all. Anyone > > > > > > > have a example or a nudge? > > > > > > > > > > > > > > -- > > > > > > > Douglas Knudsen > > > > > > > http://www.cubicleman.com <http://www.cubicleman.com> < > > > http://www.cubicleman.com <http://www.cubicleman.com> > > > > > <http://www.cubicleman.com <http://www.cubicleman.com> < > > > http://www.cubicleman.com <http://www.cubicleman.com> > > > > > > > > > this is my signature, like it? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Douglas Knudsen > > > > > > > > http://www.cubicleman.com <http://www.cubicleman.com> < > > > http://www.cubicleman.com <http://www.cubicleman.com> > > > > > > this is my signature, like it? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > Douglas Knudsen > > > http://www.cubicleman.com <http://www.cubicleman.com> > > > this is my signature, like it? > > > > > > > > > > > > > -- > A vivid and creative mind characterizes you. >
