The datagrid gets its data from a back end database which has records like
RecordID Division Department Date_Report_Submitted
1. Finance Accounting 11/1/2010
2. Engineering Design 4/2/2011
3. Engineering Implementation 4/2/2011
4. Support Chat_Support 2/4/2010
Clicking on the headers in the Datagrid column(Department) results in a sort based on recordID like
Division Department Date_Report_Submitted
Finance Accounting 11/1/2010
Engineering Design 4/2/2011
Engineering Implementation 4/2/2011
Support Chat_Support 2/4/2010
whereas I want it to be sorted alphabetically for the Datagrid column(Department) like
Division Department Date_Report_Submitted
Finance Accounting 11/1/2010
Support Chat_Support 2/4/2010
Engineering Design 4/2/2011
Engineering Implementation 4/2/2011
since Accounting should come before Chat_Support as per lexicographical order.
Looked at http://blog.flexexamples.com/2008/04/09/creating-a-custom-sort-on-a-datagrid-control-in-flex/#more-590 and have something like
<mx:DataGrid id="myRecords" dataProvider="{myRecords_dp}" width="810" height="274"
itemClick="getRecordData(event)">
<mx:columns>
<mx:DataGridColumn id="firstCol" width="180" fontFamily="Arial" fontSize="12"
wordWrap="true" />
<mx:Button label="Click to Sort" click="mysort()" />
</mx:columns>
</mx:DataGrid>
and
private function mysort():void
{
var sortField:SortField = new SortField();
sortField.compareFunction = mycompare;
sortField.descending = false;
var sort:Sort = new Sort();
sort.fields = [sortField];
myRecords.sort = sort;
myRecords.refresh();
}
private function mycompare(lhs:Object, rhs:Object):int
{
var valueA:String = lhs.text();
var valueB:String = rhs.text();
return ObjectUtil.stringCompare(valueA, valueB);
}
I get errors like
1061: Call to a possibly undefined method refresh through a reference with static type mx.controls:DataGrid.
for myRecords.refresh();
and
Access of possibly undefined property sort through a reference with static type mx.controls:DataGrid.
for myRecords.sort
Any suggestions would be appreciated.