1 Reply Latest reply on Oct 18, 2009 4:28 AM by David_F57

    Best way to "page" through data?

    Handycam Level 1

      If I have a XM, something like

       

      <people>

      <person>

      <firstname>john</firstname>

      <lastname>smith</lastname>

      </person>

      <person>

      <firstname>robert</firstname>

      <lastname>walker</lastname>

      </person>

      ...

      </people>

       

      And I create some bound fields to display this, what's the best way to "page" the data?

       

      I know I can create an XML variable of the data and then access person[0].firstname, but I need to have a button or other ui element that would choose person 0,1,2,3 etc.

       

      Normally I's use a list, but this application calls for a static screen where only the data changes when buttons are chosen.

        • 1. Re: Best way to "page" through data?
          David_F57 Level 5

          I use this method(this is simplified) as it doesn't require any sort of data services, you can have change events etc for editing/deleteing. the slider is just for poc, a prev/next button could just as easily do.

           

          <?xml version="1.0" encoding="utf-8"?>

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:s="library://ns.adobe.com/flex/spark"

          xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="800" minHeight="400" creationComplete="initApp()" width="800" height="400">

          <fx:Declarations>

          <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <fx:Script>

          <![CDATA[

          import mx.collections.ArrayCollection;

          [Bindable] private var Arr:ArrayCollection=new ArrayCollection();

          private var Sel:int = 0;

          protected function initApp(): void

          {

          Arr.addItem({id:1,name:"John",surname:"Robertson",age:30});

          Arr.addItem({id:2,name:"Peter",surname:"Williams",age:35});

          Arr.addItem({id:3,name:"Jane",surname:"Brown",age:23});

          Arr.addItem({id:4,name:"Rebecca",surname:"Smith",age:42});

          Arr.addItem({id:5,name:"Susan",surname:"Reynolds",age:25});

          Arr.addItem({id:6,name:"Michael",surname:"Royce",age:23});

          Arr.addItem({id:7,name:"Jack",surname:"Jones",age:22});

          Arr.addItem({id:8,name:"Pete",surname:"Young",age:50});

          Arr.addItem({id:9,name:"Robert",surname:"Peters",age:39});

          hs.maximum = Arr.length-1;

          hs.value = 0;

          updateList();

          }

           

          protected function updateList():void

          {

          Sel = hs.value;

          surname.text= Arr[Sel].surname;

          firstname.text= Arr[Sel].name;

          age.text= Arr[Sel].age;

          }

          ]]>

          </fx:Script>

          <s:Group width="497" height="114" horizontalCenter="0" verticalCenter="0">

          <s:TextInput id="surname" x="46" y="45"/>

          <s:TextInput id="firstname" x="182" y="45"/>

          <s:TextInput id="age" x="318" y="45"/>

          <s:HSlider id="hs" x="62" y="96" width="200" minimum="0" maximum="1" liveDragging="true" change="updateList()" value="-1"/>

            </s:Group>

          </s:Application>

           

          David