Repository: flex-sdk Updated Branches: refs/heads/develop e32044cdb -> 0cb12ee3f
FLEX-34837 CAUSE: DataGrid never had a mechanism by which it could monitor changes to the complex dataFields (e.g. "address.street") of the items in its dataProvider. Because of this, it couldn't ask for the collection to re-sort its items when one of these values changed. The best it could do was to keep track of when these values changed through its GridItemEditor, which it could detect. SOLUTION: Now ListCollectionView can be asked (by DataGrid.ensureComplexFieldsMonitoring) to monitor all changes to the complex fields by which it's sorted (through the ComplexFieldChangeWatcher). Whenever one of them changes, the collection is resorted. Also, the sorting that GridColumn used to do through one of its own sortFunctions, is now left to Sort and SortField to do, as they've specialized in complex fields as well. NOTES: -This also means that GridItemEditor doesn't need to manually dispatch an itemUpdated event each time an item has been edited through it. Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/3a1769b3 Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/3a1769b3 Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/3a1769b3 Branch: refs/heads/develop Commit: 3a1769b39e8e4f41ca84738dae76db4be62e9c53 Parents: e32044c Author: Mihai Chira <[email protected]> Authored: Sat Jul 25 14:30:45 2015 +0200 Committer: Mihai Chira <[email protected]> Committed: Sat Jul 25 14:30:45 2015 +0200 ---------------------------------------------------------------------- frameworks/projects/framework/manifest.xml | 2 + .../src/mx/collections/ListCollectionView.as | 3 +- .../spark/src/spark/components/DataGrid.as | 140 ++++++++++--------- .../spark/components/gridClasses/GridColumn.as | 76 +++------- .../components/gridClasses/GridItemEditor.as | 6 - .../components/gridClasses/GridSortField.as | 83 ----------- .../gridClasses/GridSortFieldComplex.as | 72 ++++++++++ .../gridClasses/GridSortFieldSimple.as | 45 ++++++ 8 files changed, 212 insertions(+), 215 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/framework/manifest.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/manifest.xml b/frameworks/projects/framework/manifest.xml index b27bc2a..ce26f05 100644 --- a/frameworks/projects/framework/manifest.xml +++ b/frameworks/projects/framework/manifest.xml @@ -89,6 +89,8 @@ <component id="SolidColorStroke" class="mx.graphics.SolidColorStroke"/> <component id="Sort" class="mx.collections.Sort"/> <component id="SortField" class="mx.collections.SortField"/> + <component id="ComplexSortField" class="mx.collections.ComplexSortField"/> + <component id="ComplexFieldChangeWatcher" class="mx.collections.ComplexFieldChangeWatcher"/> <component id="SoundEffect" class="mx.effects.SoundEffect"/> <component id="Spacer" class="mx.controls.Spacer"/> <component id="Sprite" class="flash.display.Sprite" lookupOnly="true"/> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/framework/src/mx/collections/ListCollectionView.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as index 1310ee2..301796b 100644 --- a/frameworks/projects/framework/src/mx/collections/ListCollectionView.as +++ b/frameworks/projects/framework/src/mx/collections/ListCollectionView.as @@ -1866,7 +1866,8 @@ public class ListCollectionView extends Proxy stopWatchingForComplexFieldsChanges(); _complexFieldWatcher = value; - _complexFieldWatcher.mx_internal::list = this; + if(_complexFieldWatcher) + _complexFieldWatcher.mx_internal::list = this; startWatchingForComplexFieldsChanges(); } http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/DataGrid.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/DataGrid.as b/frameworks/projects/spark/src/spark/components/DataGrid.as index 3d5a04f..926e0cc 100644 --- a/frameworks/projects/spark/src/spark/components/DataGrid.as +++ b/frameworks/projects/spark/src/spark/components/DataGrid.as @@ -30,10 +30,13 @@ package spark.components import flash.ui.Keyboard; import mx.collections.ArrayCollection; + import mx.collections.ComplexFieldChangeWatcher; import mx.collections.ICollectionView; + import mx.collections.IComplexSortField; import mx.collections.IList; import mx.collections.ISort; import mx.collections.ISortField; + import mx.collections.ListCollectionView; import mx.core.DragSource; import mx.core.EventPriority; import mx.core.IFactory; @@ -67,7 +70,6 @@ package spark.components import spark.components.gridClasses.GridLayout; import spark.components.gridClasses.GridSelection; import spark.components.gridClasses.GridSelectionMode; - import spark.components.gridClasses.GridSortField; import spark.components.gridClasses.GridView; import spark.components.gridClasses.IDataGridElement; import spark.components.gridClasses.IGridItemEditor; @@ -1852,7 +1854,7 @@ public class DataGrid extends SkinnableContainerBase * * @default false * - * @see #sortable + * @see #sortableColumns * @see spark.components.gridClasses.GridColumn#sortable * @langversion 3.0 @@ -3797,7 +3799,7 @@ public class DataGrid extends SkinnableContainerBase var f:Function = function(g:Grid):void { g.selectedIndex = value; - } + }; deferredGridOperations.push(f); } } @@ -4481,11 +4483,7 @@ public class DataGrid extends SkinnableContainerBase * @param columnCount If <code>selectionEventKind</code> is for a cell region, * the number of columns in the cell region. The default is -1 to * indicate this parameter is not being used. - * - * @param indices If <code>selectionEventKind</code> is for multiple rows, - * the 0-based row indices of the rows in the selection. The default is - * null to indicate this parameter is not being used. - * + * * @return <code>true</code> if the selection was committed or did not change, or * <code>false</code> if the selection was canceled or could not be committed due to * an error, such as index out of range or the <code>selectionEventKind</code> is not @@ -4782,7 +4780,7 @@ public class DataGrid extends SkinnableContainerBase } /** - * Override to make a datagrid cell editabe based on the data item. + * Override to make a datagrid cell editable based on the data item. * * @langversion 3.0 * @playerversion Flash 10 @@ -4864,46 +4862,67 @@ public class DataGrid extends SkinnableContainerBase { return new DataGridEditor(this); } - + //-------------------------------------------------------------------------- // // Sorting Methods // //-------------------------------------------------------------------------- + private function ensureComplexFieldsMonitoring(sortFields:Array):void + { + if(!(dataProvider is ListCollectionView)) + return; + + for (var i:int = 0; i < sortFields.length; i++) + { + var sortField:ISortField = sortFields[i]; + if(sortField is IComplexSortField) + break; + } + + if(i < sortFields.length) + { + if(!ListCollectionView(dataProvider).complexFieldWatcher) + ListCollectionView(dataProvider).complexFieldWatcher = new ComplexFieldChangeWatcher(); + } + else + ListCollectionView(dataProvider).complexFieldWatcher = null; + } + /** * Sort the DataGrid by one or more columns, and refresh the display. - * + * * <p>If the <code>dataProvider</code> is an ICollectionView, then it's <code>sort</code> property is * set to a value based on each column's <code>dataField</code>, <code>sortCompareFunction</code>, * and <code>sortDescending</code> flag. * Then, the data provider's <code>refresh()</code> method is called. </p> - * + * * <p>If the <code>dataProvider</code> is not an ICollectionView, then this method has no effect.</p> - * - * <p>If isInteractive is true then a <code>GridSortEvent.SORT_CHANGING</code> is dispatched before the + * + * <p>If isInteractive is true then a <code>GridSortEvent.SORT_CHANGING</code> is dispatched before the * sort is applied. Listeners can change modify the event to change the sort or cancel * the event to cancel the sort. If isInteractive is true and the sort is not cancelled, then a * <code>GridSortEvent.SORT_CHANGE</code> event is dispatched after the dataProvider's sort has been * updated.</p> - * + * * <p>If the sort has not be cancelled, the columnHeaderGroup's <code>visibleSortIndicatorIndices</code> is updated.</p> - * + * * @param columnIndices The indices of the columns by which to sort the <code>dataProvider</code>. - * + * * @param isInteractive If true, <code>GridSortEvent.SORT_CHANGING</code> and * <code>GridSortEvent.SORT_CHANGE</code> events are dispatched. - * + * * @return <code>true</code> if the <code>dataProvider</code> was sorted with the provided * column indicies. - * + * * @see spark.components.DataGrid#dataProvider * @see spark.components.gridClasses.GridColumn#sortCompareFunction * @see spark.components.gridClasses.GridColumn#sortDescending * @see spark.components.gridClasses.GridColumn#sortField * @see spark.components.GridColumnHeaderGroup#visibleSortIndicatorIndices * @see spark.events.GridSortEvent - * + * * @langversion 3.0 * @playerversion Flash 10 * @playerversion AIR 2.5 @@ -4914,19 +4933,19 @@ public class DataGrid extends SkinnableContainerBase const dataProvider:ICollectionView = this.dataProvider as ICollectionView; if (!dataProvider) return false; - + var sort:ISort = dataProvider.sort; if (sort) sort.compareFunction = null; else sort = new Sort(); - + var sortFields:Array = createSortFields(columnIndices, sort.fields); - if (!sortFields || (sortFields.length == 0)) + if (!sortFields || (sortFields.length == 0)) return false; - + var oldSortFields:Array = (dataProvider.sort) ? dataProvider.sort.fields : null; - + // Dispatch the "changing" event. If preventDefault() is called // on this event, the sort operation will be cancelled. If columnIndices or // sortFields are changed, the new values will be used. @@ -4936,35 +4955,35 @@ public class DataGrid extends SkinnableContainerBase // are copied to the new Array, not the ISortField objects themselves. if (oldSortFields) oldSortFields = oldSortFields.concat(); - + if (hasEventListener(GridSortEvent.SORT_CHANGING)) { - const changingEvent:GridSortEvent = + const changingEvent:GridSortEvent = new GridSortEvent(GridSortEvent.SORT_CHANGING, - false, true, - columnIndices, + false, true, + columnIndices, oldSortFields, /* intended to be read-only but no way to enforce this */ - sortFields); - + sortFields); + // The event was cancelled so don't sort. if (!dispatchEvent(changingEvent)) return false; - + // Update the sort columns since they might have changed. columnIndices = changingEvent.columnIndices; if (!columnIndices) return false; - + // Update the new sort fields since they might have changed. sortFields = changingEvent.newSortFields; if (!sortFields) return false; } } - + // Remove each old SortField that's not a member of the new sortFields Array // as a "styleClient" of this DataGrid. - + if (oldSortFields) { for each (var oldSortField:ISortField in oldSortFields) @@ -4975,10 +4994,10 @@ public class DataGrid extends SkinnableContainerBase removeStyleClient(oldASC); } } - + // Add new SortFields as "styleClients" of this DataGrid so that they - // inherit this DataGrid's locale style. - + // inherit this DataGrid's locale style. + for each (var newSortField:ISortField in sortFields) { var newASC:IAdvancedStyleClient = newSortField as IAdvancedStyleClient; @@ -4986,33 +5005,35 @@ public class DataGrid extends SkinnableContainerBase continue; addStyleClient(newASC); } - + + ensureComplexFieldsMonitoring(sortFields); + sort.fields = sortFields; - + dataProvider.sort = sort; dataProvider.refresh(); - + if (isInteractive) { // Dispatch the "change" event. if (hasEventListener(GridSortEvent.SORT_CHANGE)) { - const changeEvent:GridSortEvent = + const changeEvent:GridSortEvent = new GridSortEvent(GridSortEvent.SORT_CHANGE, - false, true, - columnIndices, - oldSortFields, sortFields); + false, true, + columnIndices, + oldSortFields, sortFields); dispatchEvent(changeEvent); } - + // Update the visible sort indicators. if (columnHeaderGroup) - columnHeaderGroup.visibleSortIndicatorIndices = columnIndices; - } - + columnHeaderGroup.visibleSortIndicatorIndices = columnIndices; + } + return true; } - + /** * @private * Return an array of ISortFields, one per column. If a matching sort field is found in @@ -5030,9 +5051,7 @@ public class DataGrid extends SkinnableContainerBase if (!col || (!col.dataField && (col.labelFunction == null) && (col.sortCompareFunction == null))) return null; - var dataField:String = col.dataField; - var isComplexDataField:Boolean = (dataField && (dataField.indexOf(".") != -1)); - var sortField:ISortField = findSortField(dataField, previousFields, isComplexDataField); + var sortField:ISortField = findSortField(col.dataField, previousFields); if (!sortField) { @@ -5053,27 +5072,18 @@ public class DataGrid extends SkinnableContainerBase /** * @private * Finds a SortField using the provided dataField and returns it. - * If the dataField is complex, it tries to find a GridSortField - * with a matching dataFieldPath. - * + * * @param dataField The dataField of the column. * @param fields The array of SortFields to search through. - * @param isComplexDataField true if the dataField is a path. */ - private static function findSortField(dataField:String, fields:Array, isComplexDataField:Boolean):ISortField + private static function findSortField(dataField:String, fields:Array):ISortField { if (dataField == null) return null; for each (var field:ISortField in fields) { - var name:String = field.name; - if (isComplexDataField && (field is GridSortField)) - { - name = GridSortField(field).dataFieldPath; - } - - if (name == dataField) + if (field.name == dataField) return field; } http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as index 0536ea4..afb9047 100644 --- a/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as +++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridColumn.as @@ -22,16 +22,18 @@ package spark.components.gridClasses import flash.events.Event; import flash.events.EventDispatcher; + import mx.collections.ComplexFieldChangeWatcher; + import mx.collections.ISortField; + import mx.collections.ListCollectionView; import mx.core.ClassFactory; import mx.core.IFactory; - import mx.core.mx_internal; import mx.events.CollectionEvent; import mx.events.CollectionEventKind; import mx.events.PropertyChangeEvent; import mx.formatters.IFormatter; import mx.styles.IAdvancedStyleClient; import mx.utils.ObjectUtil; - + import mx.core.mx_internal; import spark.collections.SortField; import spark.components.Grid; @@ -113,7 +115,7 @@ public class GridColumn extends EventDispatcher * @playerversion AIR 2.5 * @productversion Flex 4.5 */ - public static const ERROR_TEXT:String = new String(" "); + public static const ERROR_TEXT:String = " "; //-------------------------------------------------------------------------- // @@ -136,30 +138,6 @@ public class GridColumn extends EventDispatcher _defaultItemEditorFactory = new ClassFactory(DefaultGridItemEditor); return _defaultItemEditorFactory; } - - /** - * @private - * A default compare function for sorting if the dataField is a complex path. - */ - private static function dataFieldPathSortCompare(obj1:Object, obj2:Object, column:GridColumn):int - { - if (!obj1 && !obj2) - return 0; - - if (!obj1) - return 1; - - if (!obj2) - return -1; - - const dataFieldPath:Array = column.dataField.split("."); - const formatter:IFormatter = column.formatter; - - const obj1String:String = column.itemToString(obj1, dataFieldPath, null, formatter); - const obj2String:String = column.itemToString(obj2, dataFieldPath, null, formatter); - - return ObjectUtil.stringCompare(obj1String, obj2String); - } //-------------------------------------------------------------------------- // @@ -328,7 +306,7 @@ public class GridColumn extends EventDispatcher { dataFieldPath = [value]; } - + invalidateGrid(); if (grid) grid.clearGridLayoutCache(true); @@ -1598,62 +1576,40 @@ public class GridColumn extends EventDispatcher * @playerversion AIR 2.5 * @productversion Flex 4.5 */ - public function get sortField():SortField + public function get sortField():ISortField { const column:GridColumn = this; const isComplexDataField:Boolean = dataFieldPath.length > 1; - - // A complex dataField requires a GridSortField for the DataGrid - // to reverse a previous sort on this column by matching dataFieldPath - // to the dataField. + // TODO (klin): Might be fixed in Spark Sort. The only reason this is // required is because MX Sort RTEs when the dataField doesn't exist on the // data object even though a sortCompareFunction is defined. - var sortField:SortField; - if (isComplexDataField) - { - sortField = new GridSortField(); - GridSortField(sortField).dataFieldPath = dataField; - } - else - { - sortField = new SortField(dataField); - } + var sortField:ISortField = isComplexDataField ? new GridSortFieldComplex(this, dataField) : new GridSortFieldSimple(this, dataField); sortField.sortCompareType = column._sortCompareType; - var cF:Function = null; + var compareFunc:Function = null; if (_sortCompareFunction != null) { - cF = function (a:Object, b:Object):int + compareFunc = function (a:Object, b:Object):int { return _sortCompareFunction(a, b, column); }; } else { - // If no sortCompareFunction is specified, there are defaults for - // two special cases: complex dataFields and labelFunctions without dataFields. - - if (isComplexDataField) - { - // use custom compare function for a complex dataField if one isn't provided. - cF = function (a:Object, b:Object):int - { - return dataFieldPathSortCompare(a, b, column); - }; - } - else if (dataField == null && _labelFunction != null) + // If no sortCompareFunction is specified, there is a default for + // labelFunctions without dataFields. + if(dataField == null && _labelFunction != null) { - // use basic string compare on the labelFunction results - cF = function (a:Object, b:Object):int + compareFunc = function (a:Object, b:Object):int { return ObjectUtil.stringCompare(_labelFunction(a, column), _labelFunction(b, column)); }; } } - sortField.compareFunction = cF; + sortField.compareFunction = compareFunc; sortField.descending = column.sortDescending; return sortField; } http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/gridClasses/GridItemEditor.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridItemEditor.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridItemEditor.as index d623331..bc851ea 100644 --- a/frameworks/projects/spark/src/spark/components/gridClasses/GridItemEditor.as +++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridItemEditor.as @@ -520,13 +520,7 @@ public class GridItemEditor extends Group implements IGridItemEditor if (property && data[property] !== newData) { - var oldData:Object = data[property]; data[property] = newData; - - // If a complex field reference then the data and property local vars were modified and - // no longer point to the top-level data object and the complete path to the property - // so use the original values. - dataGrid.dataProvider.itemUpdated(this.data, column.dataField, oldData, newData); } return true; http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/gridClasses/GridSortField.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridSortField.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridSortField.as deleted file mode 100644 index 1890129..0000000 --- a/frameworks/projects/spark/src/spark/components/gridClasses/GridSortField.as +++ /dev/null @@ -1,83 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Licensed to the Apache Software Foundation (ASF) under one or more -// contributor license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright ownership. -// The ASF licenses this file to You under the Apache License, Version 2.0 -// (the "License"); you may not use this file except in compliance with -// the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -//////////////////////////////////////////////////////////////////////////////// - -package spark.components.gridClasses -{ - -import spark.collections.SortField; - -[ExcludeClass] - -/** - * A subclass of SortField used by DataGrid and GridColumn to keep track - * of complex dataFields when trying to reverse the sort. - * - * @langversion 3.0 - * @playerversion Flash 10 - * @playerversion AIR 2.5 - * @productversion Flex 4.5 - */ -public class GridSortField extends SortField -{ - //-------------------------------------------------------------------------- - // - // Constructor - // - //-------------------------------------------------------------------------- - - /** - * Constructor. - * - * @langversion 3.0 - * @playerversion Flash 10 - * @playerversion AIR 2.5 - * @productversion Flex 4.5 - */ - public function GridSortField(name:String=null, descending:Boolean=false, numeric:Object=null) - { - super(name, descending, numeric); - } - - override public function objectHasSortField(object:Object):Boolean - { - if(name && name.indexOf(".") != -1) - return object && object.hasOwnProperty(name.split(".")[0]); - else - return super.objectHasSortField(object); - } - //-------------------------------------------------------------------------- - // - // Properties - // - //-------------------------------------------------------------------------- - - /** - * The complex dataField in dot notation - * of the column associated with this SortField. - * - * If dataFieldPath is specified, the name is null. - * - * @langversion 3.0 - * @playerversion Flash 10 - * @playerversion AIR 2.5 - * @productversion Flex 4.5 - */ - public var dataFieldPath:String; -} -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldComplex.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldComplex.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldComplex.as new file mode 100644 index 0000000..e4f9bad --- /dev/null +++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldComplex.as @@ -0,0 +1,72 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package spark.components.gridClasses { + + import mx.collections.ComplexSortField; + import mx.utils.ObjectUtil; + + [ExcludeClass] + + /** + * A subclass of SortField used by DataGrid and GridColumn to keep track + * of complex dataFields when trying to reverse the sort. + * + * @langversion 3.0 + * @playerversion Flash 10 + * @playerversion AIR 2.5 + * @productversion Flex 4.5 + */ + public class GridSortFieldComplex extends ComplexSortField { + private var _column:GridColumn; + + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10 + * @playerversion AIR 2.5 + * @productversion Flex 4.5 + */ + + public function GridSortFieldComplex(column:GridColumn, name:String = null, descending:Boolean = false, numeric:Object = null) + { + _column = column; + super(name, false, descending, numeric) + } + + + override protected function getSortFieldValue(obj:Object):* + { + var unformattedValue:* = ObjectUtil.getValue(obj, nameParts); + return column && column.formatter ? column.formatter.format(unformattedValue) : unformattedValue; + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + public function get column():GridColumn + { + return _column; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/3a1769b3/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldSimple.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldSimple.as b/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldSimple.as new file mode 100644 index 0000000..72290b5 --- /dev/null +++ b/frameworks/projects/spark/src/spark/components/gridClasses/GridSortFieldSimple.as @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// + +package spark.components.gridClasses { + import mx.utils.ObjectUtil; + + import spark.collections.SortField; + + public class GridSortFieldSimple extends SortField { + private var _column:GridColumn; + + public function GridSortFieldSimple(column:GridColumn, name:String = null, descending:Boolean = false, numeric:Object = null, sortCompareType:String = null, customCompareFunction:Function = null) + { + _column = column; + super(name, descending, numeric, sortCompareType, customCompareFunction); + } + + public function get column():GridColumn + { + return _column; + } + + override protected function getSortFieldValue(obj:Object):* + { + var unformattedValue:* = ObjectUtil.getValue(obj, [name]); + return column && column.formatter ? column.formatter.format(unformattedValue) : unformattedValue; + } + } +}
