Flex 2 DataGrid page

Source: Internet
Author: User

<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" xmlns = "*" layout = "absolute" creationcomplete = "initapp ()">
<Mx: SCRIPT>
<! [CDATA [
Public var pagerecordes: uint = 8;
Public var totalpages: uint = 0;
Public var totalrows: uint = 0;
Public var currentpage: uint = 1;
Public var pagestartrow: uint = 1;
Public var pageendrow: uint = 0;

Public Function initapp (): void {
TXT. Text = "page" + currentpage;
Totalrows = initdg. length;
If (initdg. length> pagerecordes ){
DG. dataprovider = initdg. Slice (0, pagerecordes );
Ppage. Enabled = false;
}

If (totalrows % pagerecordes) = 0 ){
Totalpages = math. Floor (totalrows/pagerecordes );
} Else {
Totalpages = math. Floor (totalrows/pagerecordes + 1 );
}

If (totalrows <= pagerecordes ){
This. pagestartrow = 1;
This. pageendrow = totalrows;
} Else {
This. pagestartrow = 1;
This. pageendrow = pagerecordes;
}

If (totalpages = 1 ){
Ppage. Enabled = false;
Npage. Enabled = false;
}
}

Public Function showpreviouspage (): void {
Currentpage = currentpage-1;
TXT. Text = "page" + currentpage;
If (currentpage = 1 ){
Ppage. Enabled = false;
Npage. Enabled = true;
} Else {
Ppage. Enabled = true;
Npage. Enabled = true;
}
If (currentpage = totalpages ){
Pagestartrow = (currentpage-1) * pagerecordes + 1;
Pageendrow = totalrows;
} Else {
Pagestartrow = (currentpage-1) * pagerecordes + 1;
Pageendrow = currentpage * pagerecordes;
}
DG. dataprovider = initdg. Slice (pagestartrow-1, pageendrow );
}

Public Function shownextpage (): void {
Currentpage = currentpage + 1;
TXT. Text = "page" + currentpage;
If (currentpage = totalpages ){
Npage. Enabled = false;
Ppage. Enabled = true;
} Else {
Npage. Enabled = true;
Ppage. Enabled = true;
}
If (currentpage = totalpages ){
Pagestartrow = (currentpage-1) * pagerecordes + 1;
Pageendrow = totalrows;
} Else {
Pagestartrow = (currentpage-1) * pagerecordes + 1;
Pageendrow = currentpage * pagerecordes;
}
DG. dataprovider = initdg. Slice (currentpage-1) * pagerecordes, pageendrow );
}

Public Function showfirstpage (): void {
DG. dataprovider = initdg. Slice (0, pagerecordes );
Ppage. Enabled = false;
Npage. Enabled = true;
TXT. Text = "page" + 1;
Currentpage = 1;
}

Public Function showlastpage (): void {
DG. dataprovider = initdg. Slice (totalpages-1) * pagerecordes, totalrows );
Ppage. Enabled = true;
Npage. Enabled = false;
TXT. Text = "page" + totalpages;
Currentpage = totalpages;
}
]>
</MX: SCRIPT>
<Mx: panel title = "DataGrid panel" Height = "287" width = "500">
<Mx: DataGrid id = "DG" Height = "100%" width = "100%">
<Mx: dataprovider>
<Mx: array id = "initdg">
<Mx: Object player = "Rafer Alston" Pos = "G" from = "Fresno State"/>
<Mx: Object player = "Luther head" Pos = "G" from = "lllinois"/>
<Mx: Object player = "Tracy McGrady" Pos = "F-G" from = "Mount Zion Christian Acad. Hs (NC)"/>
<Mx: Object player = "Dikembe Mutombo" Pos = "C" from = "Georgetown"/>
<Mx: Object player = "stromile Swift" Pos = "F" from = "louisiana state"/>
<Mx: Object player = "David Wesley" Pos = "G" from = "baylor"/>
<Mx: Object player = "Yao Ming" Pos = "C" from = "China"/>
<Mx: Object player = "Kobe Bryant" Pos = "G" from = "Lower Merion HS (PA)"/>
<Mx: Object player = "Kwame Brown" Pos = "F-C" from = "Glynn Academy HS (GA)"/>
<Mx: Object player = "Lamar Odom" Pos = "F" from = "Fig Island"/>
<Mx: Object player = "Andrew Bynum" Pos = "C" from = "st. Joseph HS (NJ)"/>
<Mx: Object player = "Brian Cook" Pos = "F" from = "Illinois"/>
<Mx: Object player = "Devean George" Pos = "F" from = "Augsburg"/>
<Mx: Object player = "Devin green" Pos = "G" from = "Hampton"/>
<Mx: Object player = "Aaron mckie" Pos = "F" from = "Temple"/>
<Mx: Object player = "Chris Mihm" Pos = "C" from = "Texas"/>
<Mx: Object player = "Smush Parker" Pos = "G" from = "Fordham"/>
<Mx: Object player = "Ronny Turiaf" Pos = "F" from = "Gonzaga"/>
<Mx: Object player = "Sasha Vujacic" Pos = "F" from = "Slovenia"/>
<Mx: Object player = "von wafer" Pos = "F" from = "Florida state"/>
<Mx: Object player = "Luke Walton" Pos = "F" from = "Arizona"/>
<Mx: Object player = "Lamar Odom" Pos = "F" from = "Fig Island"/>
<Mx: Object player = "Jim Jackson" Pos = "F-G" from = "Ohio State"/>
</MX: array>
</MX: dataprovider>
</MX: DataGrid>
<Mx: Spacer/>
<Mx: hbox width = "391">
<Mx: Spacer/>
<Mx: linkbar borderstyle = "solid" color = "#000000" backgroundcolor = "# ccffff" id = "fpage" label = "firstpage" itemclick = "showfirstpage ()">
<Mx: dataprovider>
<Mx: array>
<Mx: String> firstpage </MX: String>
</MX: array>
</MX: dataprovider>
</MX: linkbar>
<Mx: linkbar borderstyle = "solid" color = "#000000" backgroundcolor = "# ccffff" id = "ppage" label = "prevpage" itemclick = "showpreviouspage ()">
<Mx: dataprovider>
<Mx: array>
<Mx: String> prepage </MX: String>
</MX: array>
</MX: dataprovider>
</MX: linkbar>
<Mx: Text id = "TXT" width = "52"/>
<Mx: linkbar borderstyle = "solid" color = "#000000" backgroundcolor = "# ccffff" id = "npage" label = "nextpage" itemclick = "shownextpage ()">
<Mx: dataprovider>
<Mx: array>
<Mx: String> nextpage </MX: String>
</MX: array>
</MX: dataprovider>
</MX: linkbar>
<Mx: linkbar borderstyle = "solid" color = "#000000" backgroundcolor = "# ccffff" id = "lpage" label = "lastpage" itemclick = "showlastpage ()">
<Mx: dataprovider>
<Mx: array>
<Mx: String> lastpage </MX: String>
</MX: array>
</MX: dataprovider>
</MX: linkbar>
</MX: hbox>
<Mx: Spacer/>
</MX: Panel>
</MX: Application>

This article from: http://www.360doc.com/showweb/0/0/468460.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.