Danko,
See below extended datagrid and sample application to do what you want. I realize its frustrating when you need to do things only to find yourself blocked in the obvious way; but there is definitely more then one way to skin a cat (so to speak). Im sure future versions of the flex framework will allow a more elegant solutions for the day to day problems we are faced with. I too often find my self perplexed at the reasoning to privatize certain functions and properties; but more often then not, a work around can be found that does not require one to rewrite the base components. Frustration is part of the learning process. Things that seem obvious are not always so. Anyway, I hope the below code and sample set you on your way to accomplishing your task. cheers jason Here is the application code::::: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:com="com.*"> <com:DataGridEX sortableColumns="true" id="DGItems" x="10" y="10" width="666" height="246"> <mx:ArrayCollection> <mx:Object ratethis="Item 1" value="2" ratethis2="Item 1" value2="1" value3="50"/> <mx:Object ratethis="Item 2" value="1" ratethis2="Item 2" value2="2" value3="120"/> <mx:Object ratethis="Item 3" value="3" ratethis2="Item 3" value2="3" value3="4"/> <mx:Object ratethis="Item 4" value="4" ratethis2="Item 4" value2="4" value3="5"/> <mx:Object ratethis="Item 5" value="2" ratethis2="Item 5" value2="5" value3="3"/> <mx:Object ratethis="Item 6" value="0" ratethis2="Item 6" value2="6" value3="0"/> <mx:Object ratethis="Item 7" value="3" ratethis2="Item 7" value2="7" value3="0"/> <mx:Object ratethis="Item 8" value="4" ratethis2="Item 8" value2="8" value3="4"/> <mx:Object ratethis="Item 9" value="5" ratethis2="Item 9" value2="9" value3="2"/> <mx:Object ratethis="Item 10" value="0" ratethis2="Item 10" value2="10" value3="3"/> </mx:ArrayCollection> <com:columns> <mx:DataGridColumn id="col1" dataField="ratethis" headerText="Rate This"/> <mx:DataGridColumn id="col2" dataField="value" headerText="Rating" /> <mx:DataGridColumn id="col3" dataField="ratethis2" headerText="Rate This 2"/> <mx:DataGridColumn id="col4" dataField="value2" headerText="Rating 2" /> </com:columns> </com:DataGridEX> </mx:Application> Here is the extended grid (place in a folder called com) package com { import mx.controls.DataGrid; import mx.events.DataGridEvent; import mx.collections.ListCollectionView; import mx.controls.dataGridClasses.DataGridColumn; import mx.collections.Sort; import mx.collections.SortField; public class DataGridEX extends DataGrid { private var collectioView:ListCollectionView; public function DataGridEX() { super(); addEventListener(DataGridEvent.HEADER_RELEASE,handleSort); } private function handleSort(event:DataGridEvent):void{ //don't let the normal sort go through event.preventDefault(); var sort:Sort = new Sort(); //get the column clicked var currentCol:DataGridColumn = DataGridColumn(event.itemRenderer.data); //reverse the current sort currentCol.sortDescending = !currentCol.sortDescending; //add the new sort to the collection so the grid can use it //to update the header display sort.fields = [new SortField(currentCol.dataField, true,currentCol.sortDescending)]; collectioView.sort = sort; //reset the colums array for our sort arrow display //to take effect columns = columns; } /** * override the setting of the dataprovider so we can get a * local listcollection set up **/ override public function get dataProvider():Object { return super.dataProvider; } override public function set dataProvider(value:Object):void { super.dataProvider = value; collectioView = ListCollectionView(value); } } } -----Message d'origine----- De : flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] la part de Danko Kozar Envoyé : jeudi 8 mars 2007 11:48 À : flexcoders@yahoogroups.com Objet : [flexcoders] Re: Are other developers hesitant to extend existing classes in Flex? Private methods and variables drive me nuts.. For example, I'd like to make a simple DataGrid change: make headers clickable without refreshing the grid (just toggle a sort icon). (I need this behaviour because I'd like to have a paging DataGrid which only propagates the sort column/direction info to a record- feching routine on a server) So, I try to remove a "collection.refresh();" line from the "sortByColumn()" function, but I can't - because it's private. Then, I try to make a new function called "sortByColumn2" (that's a copy of the first one, but without "refresh" stuff) and alter the "headerReleaseHandler" which calls it, but I can't - cause it's private. And finally, I am trying to add the following code to the constructor (yes, the constructor is public, huh.. :-)) to "neutralize" the event listener: removeEventListener(DataGridEvent.HEADER_RELEASE, headerReleaseHandler, false, EventPriority.DEFAULT_HANDLER); ... but I can't cause "headerReleaseHandler" is private and can't be seen from a subclass! And then, I give up.. :-) My conclussion is that Flex framework classes are not extensible enough and I really can't see a reason. Copying the whole DataGrid class and it's renderer, style, etc. classes isn't a solution, we all agree. If not other reason - it's not the OOP way. So, I'm tempted to go to a "C:\Program Files\Adobe\Flex Builder 2 \Flex SDK 2\frameworks\source\mx\" folder and make a global search and replace on all files in this folder. You guess... replace "private" with "protected"... :-) --- In flexcoders@yahoogroups.com, "Dana Gutride" <[EMAIL PROTECTED]> wrote: > > Recently on this list, somebody said that the Flex framework team has been > surprised at the resistance many developers have to subclassing and they'd > like to understand it better. I'd like to put my 2 cents into this > discussion because maybe we can come up with some good answers. > > I think the ability to extend the existing framework is fabulous, but I find > that I am hesitant to subclass or extend the existing classes. Recently, I > spent several days trying to override the placeSortArrow function on the > datagrid. I ended up ditching my code because there were so many private > variables used by the existing placeSortArrow() function that I would need > to rewrite most of the datagrid.as file. > > I've bought books and searched online for answers, but I haven't found > anything satisfactory yet. Maybe if there were more resources (even if we > had to pay for them), we would find more developers extending the flex > framework. > > Dana >