Sunday, April 4, 2010

multi column sorting

I am wondering if it is possbile to sort data grids in multi
columns?? For example lets say the data grid simply looks like
this:




Name
Date

Art 10/29/06

Chris 12/02/04

Bob 02/21/07

Bo 08/08/05



And i want to sort it in abc order first then within that
sort(abc order) have does be sorted again by date so that A's will
stay together, B's and so on...Is this possible and if so how?



Thanks for all the helpmulti column sorting
anyone have any suggestions for this...i could really use the
help on this one...I am thinking about using list events to do
this...is this on the right path at least???multi column sorting
does anyone have any suggestions on what to do for this???
Because i could really use the help,



Thanks
var s:Sort = new Sort();

// replace the field_name here

s.fields = [ new SortField(''Name'',true),new
SortField(''Date'',true)];

your_data_grid.dataProvider.sort = s;

your_data_grid.dataProvider.refresh();
i will try this and see if it works....
one more thing, the columns are being loaded in dynamically
is it possible to parse the names into a string and then read the
names of the columns into the sort???



Thanks
anyone have any suggestions...The datagrid i am sorting has
like 30 columns and when the user holds the ctrl key and clicks it
should allow them to sort the grid but what ever columns they
select...So how do i take the code given above by raid01 and allow
it to set fields to true as the user clicks...( i know that i have
to check to see if the ctrl key is pressed and things like that)
any suggestions would be great...



Thanks again
also mult column sorting should only happen when holding down
the ctrl key...I am messing around with this but does anyone have
any suggestions for how to handle the user clicking control and
clicking on the columns at the same time
alright i am having some trouble with this...the solution
above works if i want the datagrid to be sorted by just those two
columns...but lets say i have 6 columns and i want the user to
click the columns that they want sorted(i.e. when the hold the ctrl
key and click the mouse the columns the click are the ones that the
datagrid is sorted by)...anyone have any suggestions???
any suggestions???
here is what i have...it crashes after the first click....



rivate function ctrlCheck(ke:KeyboardEvent):void // checks to
see if the ctrl key is pressed to do a multicolumn sort.

{

if( ke.keyCode == 17) ctrlChecker =true;

else ctrlChecker = false;

}

/******************************************************************************* *********************************/

private function resortColumns(le:ListEvent):void //if there
is more than one page of results resort the columns and requery,
else just resort

{

colSortedOn = new String('''');

var sortDirection:String = new String('''');

var s:Sort=new Sort();

var count:int=0;

var arr:Array=new Array();





if(le.rowIndex == 0)//get the column sorted on and attach
that to the query and requery

{

if(ctrlChecker==true)

{

while(ctrlChecker==true)//while the user is still holding
the ctrl key

{

colSortedOn =
DataGridColumn(datagrid1.columns[le.columnIndex]).dataField.toString();


if(DataGridColumn(datagrid1.columns[le.columnIndex]).sortDescending)

{

sortLoadDirection = true;

}

else

{

sortLoadDirection = false;

}

arr[count]=new SortField(colSortedOn, true,
sortLoadDirection)

count ++;

}

for(var i:int =0; i%26lt;arr.length; i++)

{

s.fields
=arr

}

datagrid1.dataProvider.sort= s;

datagrid1.dataProvider.refresh();



}

}



else //there is no sort order taking place, the item click
was something else entirely

{

parentDocument.sortCheck = 1;

}

}

No comments:

Post a Comment