有没有人可以告诉我在FLEX中我们可以把这种类型的数据排序到哪里?
数据--
第一季度2007年第二季度2006年第二季度当我排序时我需要这样的东西。
2006年第一季2006年第二季2007年第一季2007年第二季
当我应用默认排序时,这是DataGridColumn排序的一部分
2006年第一季2007年第一季2006年第二季2007年第二季
有没有人可以让我知道你有没有逻辑,或者你之前做过这样的事情。
谢谢,库马尔
发布于 2009-07-08 22:10:10
它们是弦吗...?您可以像这样定义自己的排序函数:sortCompareFunction
dataGridColumn.sortCompareFunction = compareQuarters;
private function compareQuarters(lhs:Object, rhs:Object):int
{
var lhsArray:Array = lhs.split(" ");
var rhsArray:Array = rhs.split(" ");
if(lhsArray[2] > rhsArray[2])
{
return -1;
}
if(lhsArray[2] < rhsArray[2])
{
return 1;
}
if(lhsArray[0] > rhsArray[0])
{
return -1;
}
if(lhsArray[0] < rhsArray[0])
{
return 1;
}
return 0;
}发布于 2009-07-08 22:06:07
您将需要使用自定义排序函数,即:
<mx:DataGridColumn dataField="quarter" headerText="Quarter" width="100"
sortCompareFunction="sortQuarter"/>
public function sortQuarter(obj1:Object, obj2:Object):int{
//where obj1 and obj2 are your data objects containing the quarter strings, you'll need to parse them to compare to see which one is greater.
if(obj1 < obj2){
return -1;
}
if(obj1 == obj2){
return 0;
}
if(obj1 > obj2){
return 1;
}
}我建议只断开季度字符串的最后4个字符来比较年份,然后如果它们相同,则比较每个字符串的第一个字符。
https://stackoverflow.com/questions/1100757
复制相似问题