views:

320

answers:

1

Hi ,

Iam getting an array from Backend and he is sending the array in the same order but when iam assigning it to the dataProvider of the datagrid iam not getting in the same order .

Can somebosy suggest as to how to control the order of the columns in a datagrid .

I dont know the number of columns that iam receiving from the backend but i need to make sure that the first Column is always called DATE AND LAST COLUMN is always TOTAL .

Can somebody please suggest what to do .

Thanks, Kumar

+1  A: 

DataGrid has a columns property that you can use.

private function reorderColumns()
{
    var columns:Array = dataGrid.columns;
    var dateColumn:DataGridColumn;
    var totalColumn:DataGridColumn;

    var filter:Function = function(element:*, index:int, arr:Array) 
    {
        if(DataGridColumn(element).dataField == "DATE") 
        {
            dateColumn = element;
            return false;
        }
        if(DataGridColumn(element).dataField == "TOTAL") 
        {
            totalColumn = element;
            return false;
        }
    }

    columns.filter(filter);
    columns.unshift(dateColumn);
    columns.push(totalColumn);

    dataGrid.columns = columns;
}
CookieOfFortune
Hi ,I have an array called dataGridColumnArray() which contains all the datagrid columns .Can you please let me know how u can use the function
kumar
Hi I was trying to use this function and i was getting like Value not a function error .var reorderColumns:Array = reorderColumns(gridReportColumnsArray);i was calling the function in the above way .Can you please let me know
kumar
You're not trying to use it verbatim are you? I only wrote it as an outline.
CookieOfFortune
got the idea thanks for the reply
kumar