diff options
author | xue <> | 2006-06-27 01:31:25 +0000 |
---|---|---|
committer | xue <> | 2006-06-27 01:31:25 +0000 |
commit | 56466c36f4bbe5a1fee8d77642dc57b2366164e3 (patch) | |
tree | f45a68cda2f0bbe8794e0d1ce40e6e5d0186a701 | |
parent | b03d276f8a70675907ec8746c77c780f77f5d11a (diff) |
Added tutorial and test cases for TPager.
6 files changed, 263 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes index 55e44524..a60f67b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -834,6 +834,7 @@ demos/quickstart/protected/pages/Controls/List.page -text demos/quickstart/protected/pages/Controls/Literal.page -text demos/quickstart/protected/pages/Controls/MultiView.page -text demos/quickstart/protected/pages/Controls/NewControl.page -text +demos/quickstart/protected/pages/Controls/Pager.page -text demos/quickstart/protected/pages/Controls/Panel.page -text demos/quickstart/protected/pages/Controls/PlaceHolder.page -text demos/quickstart/protected/pages/Controls/RadioButton.page -text @@ -907,6 +908,8 @@ demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php -text demos/quickstart/protected/pages/Controls/Samples/TLiteral/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.php -text +demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.page -text +demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php -text demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.page -text demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php -text demos/quickstart/protected/pages/Controls/Samples/TPanel/hello_world.gif -text @@ -1602,6 +1605,7 @@ tests/FunctionalTests/quickstart/Controls/LabelTestCase.php -text tests/FunctionalTests/quickstart/Controls/LinkButtonTestCase.php -text tests/FunctionalTests/quickstart/Controls/ListBoxTestCase.php -text tests/FunctionalTests/quickstart/Controls/MultiViewTestCase.php -text +tests/FunctionalTests/quickstart/Controls/PagerTestCase.php -text tests/FunctionalTests/quickstart/Controls/PanelTestCase.php -text tests/FunctionalTests/quickstart/Controls/RadioButtonListTestCase.php -text tests/FunctionalTests/quickstart/Controls/RadioButtonTestCase.php -text diff --git a/demos/quickstart/protected/pages/Controls/Pager.page b/demos/quickstart/protected/pages/Controls/Pager.page new file mode 100644 index 00000000..3c74d0de --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Pager.page @@ -0,0 +1,38 @@ +<com:TContent ID="body" >
+
+<h1>TPager</h1>
+<com:DocLink ClassPath="System.Web.UI.WebControls.TPager" />
+
+<p>
+<tt>TPager</tt> creates a pager that provides UI for end-users to interactively specify which page of data to be rendered in a <tt>TDataBoundControl</tt>-derived control, such as <tt>TDataList</tt>, <tt>TRepeater</tt>, <tt>TCheckBoxList</tt>, etc. The target data-bound control is specified by the <tt>ControlToPaginate</tt> property, which must be the ID path of the target control reaching from the pager's naming container.
+</p>
+
+<p>
+Note, the target data-bound control must have its <tt>AllowPaging</tt> set to true. Otherwise the pager will be invisible. Also, in case when there is only one page of data available, the pager will also be invisible.
+</p>
+
+<p>
+<tt>TPager</tt> can display one of the following three types of user interface, specified via its <tt>Mode</tt> property:
+</p>
+<ul>
+<li><tt>NextPrev</tt> - a next page and a previous page button are rendered on each page.</li>
+<li><tt>Numeric</tt> - a list of page index buttons are rendered.</li>
+<li><tt>List</tt> - a dropdown list of page indices is rendered.</li>
+</ul>
+<p>
+These user interfaces may be further customized by configuring the following properties
+</p>
+<ul>
+<li><tt>NextPageText</tt> and <tt>PrevPageText</tt> - the label of the next/previous page button. These properties are used when the pager <tt>Mode</tt> is <tt>NextPrev</tt> or <tt>Numeric</tt>.</li>
+<li><tt>FirstPageText</tt> and <tt>LastPageText</tt> - the label of the first/last page button. If empty, the corresponding button will not be displayed. These properties are used when the pager <tt>Mode</tt> is <tt>NextPrev</tt> or <tt>Numeric</tt>.</li>
+<li><tt>PageButtonCount</tt> - the maximum number of page index buttons on a page. This property is used when the pager <tt>Mode</tt> is <tt>Numeric</tt>.</li>
+<li><tt>ButtonType</tt> - type of page buttons, either <tt>PushButton</tt> meaning normal form submission buttons, or <tt>LinkButton</tt> meaning hyperlink buttons.</li>
+</ul>
+
+<p>
+<tt>TPager</tt> raises an <tt>OnPageIndexChanged</tt> event when an end-user interacts with it and specifies a new page (e.g. by clicking on a next page button that would lead to the next page.) Developers may write handlers to respond to this event and obtain the desired new page index from the event parameter's property <tt>NewPageIndex</tt>. Using this new page index, one can feed a new page of data to the associated data-bound control.
+</p>
+
+<com:RunBar PagePath="Controls.Samples.TPager.Sample1" />
+
+</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.page b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.page new file mode 100644 index 00000000..0d61f580 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.page @@ -0,0 +1,77 @@ +<com:TContent ID="body">
+
+<h1>TPager Sample</h1>
+<p>
+The following sample displays three different pagers associated with a single TDataList control. The datalist control is enabled with custom paging, which allows it to read only one page of data each time. This is typical in DB-driven applications.
+</p>
+
+<div>
+Go to page:
+<com:TPager ID="Pager"
+ ControlToPaginate="DataList"
+ PageButtonCount="3"
+ Mode="Numeric"
+ OnPageIndexChanged="pageChanged"
+ />
+</div>
+
+<com:TDataList
+ ID="DataList"
+ AllowPaging="true"
+ AllowCustomPaging="true"
+ PageSize="2"
+ EnableViewState="true"
+ RepeatColumns="2"
+ RepeatDirection="Vertical"
+ ItemStyle.Font.Italic="true"
+ ItemStyle.BackColor="#BFCFFF"
+ HeaderStyle.BackColor="black"
+ HeaderStyle.ForeColor="white"
+ FooterStyle.BackColor="gray"
+ AlternatingItemStyle.BackColor="#E6ECFF">
+
+<prop:HeaderTemplate>
+<div style="font-weight:bold; text-align:center;">Computer Parts</div>
+</prop:HeaderTemplate>
+
+<prop:FooterTemplate>
+<div style="font-weight:bold; text-align:center;">
+Total <%# $this->Parent->PageCount %> pages.
+</div>
+</prop:FooterTemplate>
+
+<prop:ItemTemplate>
+<table border="0" width="300">
+<tr>
+ <th>ID</th><th>Name</th><th>Quantity</th><th>Price</th>
+</tr>
+<tr>
+ <td align="right"><com:TLiteral Text=<%#$this->DataItem['id'] %> /></td>
+ <td align="right"><com:TLiteral Text=<%#$this->DataItem['name'] %> /></td>
+ <td align="right"><com:TLiteral Text=<%#$this->DataItem['quantity'] %> /></td>
+ <td align="right">$<com:TLiteral Text=<%#$this->DataItem['price'] %> /></td>
+</tr>
+</table>
+</prop:ItemTemplate>
+
+</com:TDataList>
+
+<com:TPager ID="Pager2"
+ ControlToPaginate="DataList"
+ FirstPageText="9"
+ LastPageText=":"
+ Mode="NextPrev"
+ NextPageText="4"
+ PrevPageText="3"
+ Font.Name="Webdings"
+ OnPageIndexChanged="pageChanged"
+ />
+<br/>
+Choose page:
+<com:TPager ID="Pager3"
+ ControlToPaginate="DataList"
+ Mode="List"
+ OnPageIndexChanged="pageChanged"
+ />
+
+</com:TContent>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php new file mode 100644 index 00000000..e5446f60 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php @@ -0,0 +1,82 @@ +<?php
+
+class Sample1 extends TPage
+{
+ /**
+ * Returns total number of data items.
+ * In DB-driven applications, this typically requires
+ * execution of an SQL statement with COUNT function.
+ * Here we simply return a constant number.
+ */
+ protected function getDataItemCount()
+ {
+ return 19;
+ }
+
+ /**
+ * Fetches a page of data.
+ * In DB-driven applications, this can be achieved by executing
+ * an SQL query with LIMIT clause.
+ */
+ protected function getData($offset,$limit)
+ {
+ $data=array(
+ array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true),
+ array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true),
+ array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true),
+ array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false),
+ array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true),
+ array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false),
+ array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true),
+ array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true),
+ array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false),
+ array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true),
+ array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true),
+ array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false),
+ array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true),
+ array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true),
+ array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false),
+ array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true),
+ array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false),
+ array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false),
+ array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false),
+ );
+ return array_slice($data,$offset,$limit);
+ }
+
+ /**
+ * Determines which page of data to be displayed and
+ * populates the datalist with the fetched data.
+ */
+ protected function populateData()
+ {
+ $offset=$this->DataList->CurrentPageIndex*$this->DataList->PageSize;
+ $limit=$this->DataList->PageSize;
+ if($offset+$limit>$this->DataList->VirtualItemCount)
+ $limit=$this->DataList->VirtualItemCount-$offset;
+ $data=$this->getData($offset,$limit);
+ $this->DataList->DataSource=$data;
+ $this->DataList->dataBind();
+ }
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->DataList->VirtualItemCount=$this->DataItemCount;
+ $this->populateData();
+ }
+ }
+
+ /**
+ * Event handler to the OnPageIndexChanged event of pagers.
+ */
+ public function pageChanged($sender,$param)
+ {
+ $this->DataList->CurrentPageIndex=$param->NewPageIndex;
+ $this->populateData();
+ }
+}
+
+?>
\ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Standard.page b/demos/quickstart/protected/pages/Controls/Standard.page index dfaee35b..156b39e5 100644 --- a/demos/quickstart/protected/pages/Controls/Standard.page +++ b/demos/quickstart/protected/pages/Controls/Standard.page @@ -80,6 +80,10 @@ </li>
<li>
+ <a href="?page=Controls.Pager">TPager</a> generates UI that allows users to interactively specify which page of data to be displayed in a data-bound control.
+ </li>
+
+ <li>
<a href="?page=Controls.Panel">TPanel</a> represents a container for other controls on a Web page. In HTML, it is displayed as a <div> element.
</li>
diff --git a/tests/FunctionalTests/quickstart/Controls/PagerTestCase.php b/tests/FunctionalTests/quickstart/Controls/PagerTestCase.php new file mode 100644 index 00000000..2ecb3452 --- /dev/null +++ b/tests/FunctionalTests/quickstart/Controls/PagerTestCase.php @@ -0,0 +1,58 @@ +<?php
+
+class PagerTestCase extends SeleniumTestCase
+{
+ function test()
+ {
+ $this->open("../../demos/quickstart/index.php?page=Controls.Samples.TPager.Sample1&notheme=true", "");
+
+ // verify datalist content
+ $this->verifyTextPresent('ITN001','');
+ $this->verifyTextPresent('ITN002','');
+ $this->verifyTextNotPresent('ITN003','');
+
+ // verify numeric paging
+ $this->clickAndWait("ctl0_body_Pager_ctl1", ""); // 2nd page
+ $this->verifyTextPresent('ITN003','');
+ $this->verifyTextPresent('ITN004','');
+ $this->verifyTextNotPresent('ITN002','');
+ $this->verifyTextNotPresent('ITN005','');
+ $this->clickAndWait("ctl0_body_Pager_ctl3", ""); // 4rd page
+ $this->verifyTextPresent('ITN007','');
+ $this->verifyTextPresent('ITN008','');
+ $this->verifyTextNotPresent('ITN006','');
+ $this->verifyTextNotPresent('ITN009','');
+ $this->clickAndWait("ctl0_body_Pager_ctl6", ""); // last page
+ $this->verifyTextPresent('ITN019','');
+ $this->verifyTextNotPresent('ITN018','');
+ $this->verifyTextNotPresent('ITN001','');
+
+ // verify next-prev paging
+ $this->clickAndWait("ctl0_body_Pager2_ctl1", ""); // prev page
+ $this->verifyTextPresent('ITN017','');
+ $this->verifyTextPresent('ITN018','');
+ $this->verifyTextNotPresent('ITN019','');
+ $this->verifyTextNotPresent('ITN016','');
+ $this->clickAndWait("ctl0_body_Pager2_ctl0", ""); // first page
+ $this->verifyTextPresent('ITN001','');
+ $this->verifyTextPresent('ITN002','');
+ $this->verifyTextNotPresent('ITN003','');
+ $this->clickAndWait("ctl0_body_Pager2_ctl2", ""); // next page
+ $this->verifyTextPresent('ITN003','');
+ $this->verifyTextPresent('ITN004','');
+ $this->verifyTextNotPresent('ITN002','');
+ $this->verifyTextNotPresent('ITN005','');
+
+ $this->verifySelected("ctl0_body_Pager3_ctl0","label=2");
+ $this->selectAndWait("ctl0_body_Pager3_ctl0", "label=5");
+ $this->verifyTextPresent('ITN009','');
+ $this->verifyTextPresent('ITN010','');
+ $this->verifyTextNotPresent('ITN008','');
+ $this->verifyTextNotPresent('ITN011','');
+ $this->selectAndWait("ctl0_body_Pager3_ctl0", "label=10");
+ $this->verifyTextPresent('ITN019','');
+ $this->verifyTextNotPresent('ITN018','');
+ }
+}
+
+?>
\ No newline at end of file |