Objective is to show a predefined number of records from the
database and
Populate a datagride.Say there are 50 records in the
database and the
requirement is to show 10 at time. As per documentaion
JavaAdaper needs to be used with page size defined. Tried but it
always return all the rows.
Code:
Mxml file
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"xmlns="*" pageTitle="Contact Manager"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
import samples.contact.*;
[Bindable]
public var contacts:ArrayCollection;
[Bindable]
public var contact:Contact;
private var ds:DataService;
private function initApp():void
{
var i:int;
contacts = new ArrayCollection();
ds = new DataService("contact");
ds.pageSize=4;
ds.autoCommit = false;
ds.fill(contacts);
AsyncToken(ds.fill(contacts));
token.kind = "fill";
}
]]>
</mx:Script>
<mx:DataGrid id="dg" dataProvider="{contacts}"
width="100%" height="100%"
change="contact=Contact(dg.selectedItem)" editable="true" >
<mx:columns>
<mx:DataGridColumn dataField="contactId"
headerText="Id"/>
<mx:DataGridColumn dataField="firstName"
headerText="First Name"/>
<mx:DataGridColumn dataField="lastName" headerText="Last
Name"/>
</mx:columns>
</mx:DataGrid>
Flex-data-service.xml
<destination id="contact">
<adapter ref="java-dao" />
<properties>
<source>samples.contact.ContactAssembler</source>
<scope>request</scope>
<metadata>
<identity property="contactId"/>
</metadata>
<network>
<session-timeout>2</session-timeout>
<paging enabled="true" pageSize="10"/>
<throttle-inbound policy="ERROR" max-frequency="500"/>
<throttle-outbound policy="REPLACE"
max-frequency="500"/>
</network>
<server>
<fill-method>
<name>loadContacts</name>
</fill-method>
<fill-method>
<name>loadContacts</name>
<params>java.lang.String</params>
</fill-method>
<sync-method>
<name>syncContacts</name>
</sync-method>
</server>
</properties>
</destination>