Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question problem in Datagrid sorting with Pagination

    I am new to flex action script coding .
    I have followed the below links for Datagrid paging.

    http://gurufaction.blogspot.com/2007...mple-with.html
    http://develop.gurufaction.com/src/App.mxml

    But facing problem in sorting. it limits the sort to the current page only.


    Below i am attaching the sample code for paging and the sorting which i have tried. Paging is working fine but problem in sorting.
    Can any body help me out to fix this problem.
    .....................................................

    <?xml version="1.0" encoding="utf-8" ?>
    - <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="InitApp()" xmlns:MyComp="*">
    - <mx:Script>
    - <![CDATA[
    import mx.collections.ArrayCollection;
    import mx.events.ItemClickEvent;
    import mx.controls.Button;
    import mx.controls.Alert;

    [Bindable]
    public var myData:ArrayCollection = new ArrayCollection();
    public var orgData:ArrayCollection = new ArrayCollection();
    [Bindable]
    public var nav:ArrayCollection = new ArrayCollection();
    public var pageSize:uint = 10;
    public var navSize:uint = 10;
    private var index:uint = 0;
    private var navPage:uint = 1;
    private var sortId:SortField;
    private var sortName:SortField;
    private var sortStreet:SortField;
    private var sortTitle:SortField;
    private var sortCity:SortField;
    var sortA:Sort

    private function InitApp():void
    {
    for( var x:uint = 1; x <= 500; x++ )
    {
    var obj:Object = new Object();
    obj.Id = x.toString();
    obj.Name = "Column " + x.toString();
    obj.Street = "5555 Street";
    obj.Title = "CEO";
    obj.City = "El Paso";

    orgData.addItem(obj);
    }

    //******** Added the extra line for sorting **********//
    sortA = new Sort();


    sortId = new SortField("Id", false,true, true);
    sortName = new SortField("Name", true);
    sortStreet = new SortField("Street", true);
    sortTitle = new SortField("Title", true);
    sortCity = new SortField("City", true);


    sortA.fields=[sortId, sortName, sortStreet, sortTitle, sortCity];
    orgData.sort=sortA;

    orgData.refresh();
    //**************************//

    refreshDataProvider(index);
    createNavBar(Math.ceil(orgData.length/pageSize));
    }

    private function createNavBar(pages:uint = 1,set:uint = 0):void
    {
    nav.removeAll();
    if( pages > 1 )
    {
    if( set != 0 )
    {
    nav.addItem({label:"<<",data:0});
    if( (set - navSize ) >= 0 )
    {
    nav.addItem({label:"<",data:set - navSize});
    }
    else
    {
    nav.addItem({label:"<",data:0});
    }
    }

    for( var x:uint = 0; x < navSize; x++)
    {
    var pg:uint = x + set;
    nav.addItem({label: pg + 1,data: pg});
    }
    if( pg < pages - 1 )
    {
    nav.addItem({label:">",datag + 1});
    nav.addItem({label:">>",dataages - pageSize});
    }
    }
    }

    private function navigatePage(event:ItemClickEvent):void
    {
    refreshDataProvider(event.item.data);
    var lb:String = event.item.label.toString();
    if( lb.indexOf("<") > -1 || lb.indexOf(">") > -1 )
    {
    createNavBar(Math.ceil(orgData.length/pageSize),event.item.data);
    if( event.item.data == 0 )
    {
    pageNav.selectedIndex = 0;
    }
    else
    {
    pageNav.selectedIndex = 2;
    }
    }

    }

    private function refreshDataProvider(start:uint):void
    {
    myData = new ArrayCollection( orgData.source.slice((start * pageSize),(start * pageSize) + pageSize) );
    }

    //**********Added for sorting *****************//

    private function headRelEvt(eventataGridEvent):void {

    sortA.fields[0]=[new SortField(event.dataField.toString())];
    orgData.sort=sortA;
    orgData.refresh();
    event.preventDefault();
    }


    ]]>
    </mx:Script>
    - <mx:VBox verticalGap="0">
    <mxataGrid id="dg" dataProvider="{myData}" />
    <mx:ToggleButtonBar id="pageNav" itemClick="navigatePage(event)" dataProvider="{nav}" width="{dg.width}" headerRelease="headRelEvt(event);" />
    </mx:VBox>
    </mx:Application>
    Last edited by laxmana.lenka; 02-17-2009 at 06:30 AM.

  • #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Please move to Flex forum, or remove the duplicate posts.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •