Need help with datagrids...

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

Need help with datagrids...

Postby Devon » 16 Apr 2011, 02:40

I'm trying to make a room list using a datagrid. With the exmaple code, I've manages to almost get it working but I'm new to Flex/AS. I'm kinda stuck and I'd appreciate some guidance.

Thanks :)

----------------------------

The problem:
It's successfully adding the proper number of new rows as I can see it'll let me highlight the first 3 when I mouseover them. However, the rows are empty and have no data in them.

trace(datagrid) outputs:

Code: Select all

[Room: Zone, Id: 2, GroupId: default],[Room: Apple, Id: 1, GroupId: default],[Room: Lobby, Id: 0, GroupId: default]


Code: Select all

private function populateRoomsLists(groupId:String):void
{
   var roomList:Array = _conn.roomManager.getRoomListFromGroup(groupId);
   var dataProvider:ArrayCollection = new ArrayCollection(roomList);
   var sort:Sort = new Sort();
   
   sort.fields = [new SortField("name")];
   dataProvider.sort = sort;
   trace(dataProvider);
   
   var datagrid:DataGrid = getRoomListFromGroup(groupId);
   
   if (datagrid != null)
   {
      datagrid.dataProvider = dataProvider;
      dataProvider.refresh();
   }
}

private function getRoomListFromGroup(groupId:String):DataGrid
{
   if (groupId == DEFAULT_GROUP)
   {
      return ls_defaultRooms;
   }
   else
   {
      return null;
   }
}


Code: Select all

   <mx:ViewStack x="0" y="0" id="viewstack" width="100%" height="100%">
      <s:NavigatorContent label="splash" width="100%" height="100%" backgroundColor="#1E1E1E" showEffect="FadeIn" hideEffect="FadeOut">
         <s:VGroup x="0" y="0" width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
            <components:splash id="splash">
            </components:splash>
         </s:VGroup>
      </s:NavigatorContent>
      <s:NavigatorContent id="main" width="100%" height="100%" showEffect="FadeIn" hideEffect="FadeOut" backgroundColor="#1E1E1E">
         <mx:DataGrid x="374" y="302" id="ls_defaultRooms">
            <mx:columns>
               <mx:DataGridColumn headerText="Room" dataField="Room"/>
            </mx:columns>
         </mx:DataGrid>
      </s:NavigatorContent>
   </mx:ViewStack>
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 18 Apr 2011, 09:13

Not sure if passing the array returned by _conn.roomManager.getRoomListFromGroup(groupId) to the dataprovider directly works.
Anyway, first of all you should enter the right value in the dateField property of the DataGridColum. I think it should be "name", which makes the datagrid look for the Room.name property.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Baidu [Spider] and 104 guests