0 Replies Latest reply on Dec 14, 2015 3:40 AM by RaviJasti

    Sorting and grouping using flash builder

    RaviJasti

      We are facing an issue when we enable sorting and grouping for a columns of the table.

       

      When we enable both, it groups the data successfully but does not sort it.

      Upon refreshing it, the data gets sorted.

       

      I have observed that same flow of code is executed when we load data or refresh data.

      The data groups and sorts while refreshing whereas it does not sort and only group while loading.

       

      Following code snippet for your reference:

      public function displayTable():void{

       

        //to showing columns in order

        //sortColumns();

        Alert.show("TabContent=>displayTable Begins");

        CursorManager.setBusyCursor();

        loading = true;

       

        try{

        var dgc:MDataGridColumn;

        var aColumnsNew:Array = new Array(); //grid.columns;

       

        var sortList:ArrayCollection = new ArrayCollection();

       

        var groupingApplied:Boolean = false;

       

        for(var i:Number = 0;i <report.columns.length; i++){

        var col:ReportColumn = report.columns[i] as ReportColumn;

       

       

       

        if(col.groupEnabled)

        groupingApplied = true;

       

       

        dgc= new MDataGridColumn(col);

       

       

        if(col.columnSortNumber>=0){

        sortList.addItem(col);

        Alert.show("Sorted Column: " +col.columnName + "at index :" + (col.columnSortNumber));

        }

       

        if(col.filterType==null || col.filterType.length==0 || groupingApplied){

        dgc.headerRenderer = new ClassFactory(AdvancedDataGridHeaderRenderer);

        }

       

       

        dgc.dataField = col.columnName;

        dgc.headerText = col.columnLable;

        dgc.width = col.columnWidth;

        dgc.visible = col.visible;

        dgc.setStyle("textAlign", col.textAlign);

       

       

        if((col.drillDown!=null && col.drillDown.length >0) || (col.ToDrilldownType!="R" && col.drillDownField!=null && col.drillDownField.length>0)){

       

        var drillItemRendererFactory:ClassFactory = new ClassFactory(GridDrilldownItemRenderer);

        drillItemRendererFactory.properties = {col:col, mainApp:this};

        dgc.itemRenderer = drillItemRendererFactory;

        }

        else if(col.condFormats.condition!=null && col.condFormats.condition.length>0 && col.condFormats.value1!=null && col.condFormats.value1.length>0){

        var condItemRendererFactory:ClassFactory = new ClassFactory(CondFormatRenderer);

        condItemRendererFactory.properties = {col:col}

        dgc.itemRenderer = condItemRendererFactory;

        }

        else if(col.subTotalAggr!=null && col.subTotalAggr.length>0){

        var summaryItemRendererFactory:ClassFactory = new ClassFactory(SummaryItemRenderer);

        summaryItemRendererFactory.properties = {col:col}

        dgc.itemRenderer = summaryItemRendererFactory;

        }

       

       

        //Grand Totals

        if(col.visible){

        var gc:AdvancedDataGridColumn = new AdvancedDataGridColumn();

        gc.dataField = col.columnName;

        gc.headerText = col.columnLable;

        gc.width = col.columnWidth;

       

        gc.visible = col.visible;

        gc.setStyle("textAlign", col.textAlign);

       

       

        if(col.grandTotalAggr!=null && col.grandTotalAggr.length>0){

        if("SUM"==col.grandTotalAggr)

        gc.labelFunction = sumFunction;

        else if("AVG"==col.grandTotalAggr)

        gc.labelFunction = averageFunction;

        else if("COUNT"==col.grandTotalAggr)

        gc.labelFunction = countFunction;

        else if("MIN"==col.grandTotalAggr)

        gc.labelFunction = minFunction;

        else if("MAX"==col.grandTotalAggr)

        gc.labelFunction = maxFunction;

        }

       

        dgc.footerColumn = gc;

        }

       

        dgc.formatter = col._formatter;

       

        if(!col.groupEnabled){

        if(col.filterType=="W"){

        dgc.filterEditor=new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.WildcardFilterEditor);

        }

        else if(col.filterType=="N")

        dgc.filterEditor=new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.NumberRangeFilterEditor);

        else if(col.filterType=="NS")

        dgc.filterEditor=new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.SliderFilterEditor);

        else if(col.filterType=="DL")

        dgc.filterEditor=new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.MultipleChoiceFilterEditor);

        else if(col.filterType=="D"){

        dgc.filterEditor = new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.DateRangeFilterEditor);

        }

        else if(col.filterType=="DC")

        dgc.filterEditor=new ClassFactory(com.rwb.controls.dataGridClasses.filterEditors.DateChooserFilterEditor);

        }

       

        aColumnsNew.push(dgc);

        //}

        }

       

        Alert.show("displayTable call sortList length:  " + sortList.length);

        setDataProvider(aColumnsNew);

       

        try{

        if(sortList.length>0){

        var dataSortField:SortField = new SortField();

        dataSortField.name = "columnSortNumber";

        dataSortField.numeric = true;

        var numericDataSort:Sort = new Sort();

        numericDataSort.fields = [dataSortField];

        sortList.sort = numericDataSort;

        sortList.refresh();

       

       

       

        var sortList1:ArrayList = new ArrayList();

        for(var i:Number = 0;i <sortList.length; i++){

       

        var col:ReportColumn = sortList[i] as ReportColumn;

        Alert.show("displayTable: sortList -> i val:" + i +  " columnName: " + col.columnName + " columnDataType " + col.columnDataType);

        var sf:SortField = null;

        if(col.columnDataType=="NUMBER" || col.columnDataType=="DATE"){

        sf = new SortField(col.columnName);

        sf.name = col.columnName;

        sf.numeric = true;

        sf.descending = (col.columnSortType=="ASC" ? false : true);

        }

        else{

        sf = new SortField(col.columnName, true,(col.columnSortType=="ASC" ? false :true));

        }

       

        sortList1.addItem(sf);

        Alert.show("displayTable: added item = " + sortList1.getItemAt(0));

       

       

        }

       

        var sort:Sort = new Sort();

        sort.fields =  sortList1.toArray();

        grid.dataProvider.sort  = sort;

        grid.dataProvider.refresh();

       

       

        }

       

       

       

        }catch(e:Error){}

       

       

        var filtersExecuted:Boolean =  grid.applyFilters();

       

        }catch(e:Error){

        Alert.show(e.message);

       

        }

       

        CursorManager.removeBusyCursor()

        loading = false;

       

        Alert.show("TabContent->displayTable Ends");

        }

       

       

      Kindly suggest.

       

      Regards,

      Ravi.