summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-02-05 03:48:45 +0000
committerxue <>2006-02-05 03:48:45 +0000
commit08bf73e5621cdc384db7c416e6e8b689123bb3a8 (patch)
tree81e9174731b53b2924ccc24804c50cc6d7e0b47d
parent9bf518fc15ed3945b8f770bd10c855a89c7707bc (diff)
Added paging example of TDataGrid.
-rw-r--r--.gitattributes2
-rw-r--r--demos/quickstart/protected/pages/Controls/DataGrid2.page17
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.page55
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php63
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php16
5 files changed, 143 insertions, 10 deletions
diff --git a/.gitattributes b/.gitattributes
index 3e1a7e86..772e65f1 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -128,6 +128,8 @@ demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page -text
demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php -text
demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page -text
demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php -text
+demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.page -text
+demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php -text
demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.page -text
demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php -text
demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.page -text
diff --git a/demos/quickstart/protected/pages/Controls/DataGrid2.page b/demos/quickstart/protected/pages/Controls/DataGrid2.page
index a081fa46..4c295f5a 100644
--- a/demos/quickstart/protected/pages/Controls/DataGrid2.page
+++ b/demos/quickstart/protected/pages/Controls/DataGrid2.page
@@ -21,7 +21,22 @@ The following example turns the datagrid in <a href="?page=Controls.Samples.TDat
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample4" />
<h2>Paging</h2>
-
+<p>
+When dealing with large datasets, paging is helpful in reducing the page size and complexity. TDataGrid has an embedding paging feature. By setting <tt>AllowPaging</tt> to true, a pager is displayed automatically at the bottom of the datagrid. The pager can be further customized by setting <tt>PagerStyle</tt>, through which you can set pager visibility, mode, position, etc.
+</p>
+<p>
+When users click on a pager button, TDataGrid raises <tt>OnPageIndexChanged</tt> event. Typically, the event handler is written as follows,
+</p>
+<com:TTextHighlighter CssClass="source">
+public function pageIndexChanged($sender,$param) {
+ $this->DataGrid->CurrentPageIndex=$param->NewPageIndex;
+ $this->DataGrid->DataSource=$this->Data;
+ $this->DataGrid->dataBind();
+}
+</com:TTextHighlighter>
+<p>
+The following example enables the paging functionality of the datagrid shown in <a href="?page=Controls.Samples.TDataGrid.Sample1">Example 1</a>. In this example, you can set various pager styles interactively to see how they affect the pager display.
+</p>
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample5" />
<h3>Custom Paging</h3>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.page
new file mode 100644
index 00000000..17f2c5d4
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.page
@@ -0,0 +1,55 @@
+<com:TContent ID="body">
+
+<h1>TDataGrid Sample 5</h1>
+<h2>Paging</h2>
+
+<com:TDataGrid
+ ID="DataGrid"
+ AllowPaging="true"
+ PageSize="5"
+ PagerStyle.Mode="Numeric"
+ PagerStyle.HorizontalAlign="Right"
+ Width="500px"
+ CellPadding="2"
+ HeaderStyle.BackColor="black"
+ HeaderStyle.ForeColor="white"
+ ItemStyle.BackColor="#BFCFFF"
+ ItemStyle.Font.Italic="true"
+ AlternatingItemStyle.BackColor="#E6ECFF"
+ OnPageIndexChanged="changePage"
+ OnItemCreated="itemCreated"
+ />
+
+<com:TPanel GroupingText="Pager Visibility" Width="300px">
+
+<com:TCheckBoxList
+ AutoPostBack="true"
+ RepeatColumns="2"
+ OnSelectedIndexChanged="changePagerPosition">
+ <com:TListItem Text="Top" />
+ <com:TListItem Text="Bottom" Selected="true" />
+</com:TCheckBoxList>
+
+</com:TPanel>
+
+<com:TPanel GroupingText="Pager Mode" Width="300px">
+
+<com:TPanel GroupingText="NextPrev Pager" Width="300px">
+
+Next Page Text:
+<com:TTextBox ID="NextPageText" Text="Next" /><br/>
+Prev Page Text:
+<com:TTextBox ID="PrevPageText" Text="Prev" /><br/>
+<com:TButton Text="Submit" OnClick="useNextPrevPager" />
+</com:TPanel>
+
+<com:TPanel GroupingText="Numeric Pager" Width="300px">
+
+Page Button Count:
+<com:TTextBox ID="PageButtonCount" Text="5" /><br/>
+<com:TButton Text="Submit" OnClick="useNumericPager" />
+</com:TPanel>
+
+</com:TPanel>
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php
new file mode 100644
index 00000000..6d6d967c
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php
@@ -0,0 +1,63 @@
+<?php
+
+Prado::using('Application.pages.Controls.Samples.TDataGrid.Sample1');
+
+class Sample5 extends Sample1
+{
+ public function changePage($sender,$param)
+ {
+ $this->DataGrid->CurrentPageIndex=$param->NewPageIndex;
+ $this->DataGrid->DataSource=$this->Data;
+ $this->DataGrid->dataBind();
+ }
+
+ public function itemCreated($sender,$param)
+ {
+ $item=$param->Item;
+ if($item->ItemType==='Pager')
+ {
+ // prepend 'Page: ' to the pager
+ $item->Cells[0]->Controls->insertAt(0,'Page: ');
+ }
+ }
+
+ public function changePagerPosition($sender,$param)
+ {
+ $top=$sender->Items[0]->Selected;
+ $bottom=$sender->Items[1]->Selected;
+ if($top && $bottom)
+ $position='TopAndBottom';
+ else if($top)
+ $position='Top';
+ else if($bottom)
+ $position='Bottom';
+ else
+ $position='';
+ if($position==='')
+ $this->DataGrid->PagerStyle->Visible=false;
+ else
+ {
+ $this->DataGrid->PagerStyle->Position=$position;
+ $this->DataGrid->PagerStyle->Visible=true;
+ }
+ }
+
+ public function useNumericPager($sender,$param)
+ {
+ $this->DataGrid->PagerStyle->Mode='Numeric';
+ $this->DataGrid->PagerStyle->PageButtonCount=$this->PageButtonCount->Text;
+ $this->DataGrid->DataSource=$this->Data;
+ $this->DataGrid->dataBind();
+ }
+
+ public function useNextPrevPager($sender,$param)
+ {
+ $this->DataGrid->PagerStyle->Mode='NextPrev';
+ $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text;
+ $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text;
+ $this->DataGrid->DataSource=$this->Data;
+ $this->DataGrid->dataBind();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index 91b0c374..b0dafb5d 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -605,9 +605,9 @@ class TDataGrid extends TBaseDataList implements INamingContainer
else if(strcasecmp($command,'page')===0)
{
$p=$param->getCommandParameter();
- if(strcasecmp($p,'next'))
+ if(strcasecmp($p,'next')===0)
$pageIndex=$this->getCurrentPageIndex()+1;
- else if(strcasecmp($p,'prev'))
+ else if(strcasecmp($p,'prev')===0)
$pageIndex=$this->getCurrentPageIndex()-1;
else
$pageIndex=TPropertyValue::ensureInteger($p)-1;
@@ -812,11 +812,10 @@ class TDataGrid extends TBaseDataList implements INamingContainer
protected function restoreGridFromViewState()
{
$this->reset();
- if(($itemCount=$this->getViewState('ItemCount',0))<=0)
- return;
+ $itemCount=$this->getViewState('ItemCount',0);
$this->_pagedDataSource=$ds=$this->createPagedDataSource();
$allowPaging=$ds->getAllowPaging();
- if($allowPaging)
+ if($allowPaging && $ds->getAllowCustomPaging())
$ds->setDataSource(new TDummyDataSource($itemCount));
else
$ds->setDataSource(new TDummyDataSource($this->getViewState('DataSourceCount',0)));
@@ -826,7 +825,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer
$items=$this->getItems();
$items->clear();
- if($columns->getCount()>0)
+ if(($columnCount=$columns->getCount())>0)
{
foreach($columns as $column)
$column->initialize();
@@ -1239,15 +1238,14 @@ class TDataGrid extends TBaseDataList implements INamingContainer
if($pagerStyle)
{
$item->getStyle()->mergeWith($pagerStyle);
- $mode=$pagerStyle->getMode();
if($index===0)
{
- if($mode==='Bottom')
+ if($pagerStyle->getPosition()==='Bottom' || !$pagerStyle->getVisible())
$item->setVisible(false);
}
else
{
- if($mode==='Top')
+ if($pagerStyle->getPosition()==='Top' || !$pagerStyle->getVisible())
$item->setVisible(false);
}
}