Renderer that doesn't change dataprovider
Is there a way to apply a renderer to a grid in a way so that it doesn't modify the values in the data provider? I have a datagrid and on one of its columns I have a customer rend开发者_如何转开发erer which overrides the set data function and converts the number value in the dataprovider to a word. My problem is that when I sort the grid by that column it sorts by the new value, whereas I want it to sort by the old value that was originally in the dataprovider.
Here is my renderer:
public class MyRenderer extends Text {
override public function set data(value:Object):void {
super.data = value;
data[DataGridListData(listData).dataField] = MyClass.convertValue(data[DataGridListData(listData).dataField]);
super.invalidateDisplayList();
}
}
The problem is this line:
data[DataGridListData(listData).dataField] = MyClass.convertValue(data[DataGridListData(listData).dataField]);
Right there, you are setting the field value to a different value.
Instead of using a custom renderer, just use a labelFunction that does a convertValue on that field. Then the non-custom renderer will simply take the label value from the DataGridListData and use it for the displayed value.
ItemRenderers, by default, do not modify dataProviders. Since you didn't show code it's hard to tell whether or not the code you've written modified the dataProvider.
I you want to sort a DataGrid based on values in the dataProvider that have no relation on the values displayed in the grid; you should use a sortCompareFunction on the DataGrid.
精彩评论