summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--demos/quickstart/protected/pages/Controls/DataGrid2.page10
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.page24
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php56
-rw-r--r--framework/Collections/TPagedDataSource.php6
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php14
6 files changed, 100 insertions, 12 deletions
diff --git a/.gitattributes b/.gitattributes
index 772e65f1..2737732c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -130,6 +130,8 @@ 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/TDataGrid/Sample6.page -text
+demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.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 4c295f5a..1a55c213 100644
--- a/demos/quickstart/protected/pages/Controls/DataGrid2.page
+++ b/demos/quickstart/protected/pages/Controls/DataGrid2.page
@@ -22,10 +22,10 @@ The following example turns the datagrid in <a href="?page=Controls.Samples.TDat
<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.
+When dealing with large datasets, paging is helpful in reducing the page size and complexity. TDataGrid has an embedded pager that allows users to specify which page of data they want to see. The pager can be customized via <tt>PagerStyle</tt>. For example, <tt>PagerStyle.Visible</tt> determines whether the pager is visible or not; <tt>PagerStyle.Position</tt> indicates where the pager is displayed; and <tt>PagerStyle.Mode</tt> specifies what type of pager is displayed, a numeric one or a next-prev one.
</p>
<p>
-When users click on a pager button, TDataGrid raises <tt>OnPageIndexChanged</tt> event. Typically, the event handler is written as follows,
+To enable paging, set <tt>AllowPaging</tt> to true. The number of rows of data displayed in a page is specified by <tt>PageSize</tt>, while the index (zero-based) of the page currently showing to users is by <tt>CurrentPageIndex</tt>. 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) {
@@ -40,6 +40,12 @@ The following example enables the paging functionality of the datagrid shown in
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample5" />
<h3>Custom Paging</h3>
+<p>
+The paging functionality shown above requires loading all data into memory, even though only a portion of them is displayed in a page. For large datasets, this is inefficient and may not always be feasible. TDataGrid provides custom paging to solve this problem. Custom paging only requires the portion of the data to be displayed to end users.
+</p>
+<p>
+To enable custom paging, set both <tt>AllowPaging</tt> and <tt>AllowCustomPaging</tt> to true. Notify TDataGrid the total number of data items (rows) available by setting <tt>VirtualItemCount</tt>. And respond to the <tt>OnPageIndexChanged</tt> event. In the event handler, use the <tt>NewPageIndex</tt> property of the event parameter to fetch the new page of data from data source. For MySQL database, this can be done by using <tt>LIMIT</tt> clause in an SQL select statement.
+</p>
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample6" />
<h2>Extending TDataGrid</h2>
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.page
new file mode 100644
index 00000000..c8a8c9a2
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.page
@@ -0,0 +1,24 @@
+<com:TContent ID="body">
+
+<h1>TDataGrid Sample 6</h1>
+<h2>Custom Paging</h2>
+
+<com:TDataGrid
+ ID="DataGrid"
+ AllowPaging="true"
+ AllowCustomPaging="true"
+ VirtualItemCount="19"
+ 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"
+ />
+
+</com:TContent> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php
new file mode 100644
index 00000000..90e3f7fe
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php
@@ -0,0 +1,56 @@
+<?php
+
+Prado::using('Application.pages.Controls.Samples.TDataGrid.Sample1');
+
+class Sample6 extends Sample1
+{
+ /**
+ * Returns a subset of data.
+ * In MySQL database, this can be replaced by LIMIT clause
+ * in an SQL select statement.
+ * @param integer the starting index of the row
+ * @param integer number of rows to be returned
+ * @return array subset of data
+ */
+ protected function getDataRows($offset,$rows)
+ {
+ $data=$this->getData();
+ $page=array();
+ for($i=0;$i<$rows;++$i)
+ {
+ if($offset+$i<$this->getRowCount())
+ $page[$i]=$data[$offset+$i];
+ }
+ return $page;
+ }
+
+ /**
+ * Returns total number of data rows.
+ * In real DB applications, this may be replaced by an SQL select
+ * query with count().
+ * @return integer total number of data rows
+ */
+ protected function getRowCount()
+ {
+ return 19;
+ }
+
+ public function onLoad($param)
+ {
+ if(!$this->IsPostBack)
+ {
+ $this->DataGrid->DataSource=$this->getDataRows(0,$this->DataGrid->PageSize);
+ $this->DataGrid->dataBind();
+ }
+ }
+
+ public function changePage($sender,$param)
+ {
+ $this->DataGrid->CurrentPageIndex=$param->NewPageIndex;
+ $offset=$param->NewPageIndex*$this->DataGrid->PageSize;
+ $this->DataGrid->DataSource=$this->getDataRows($offset,$this->DataGrid->PageSize);
+ $this->DataGrid->dataBind();
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Collections/TPagedDataSource.php b/framework/Collections/TPagedDataSource.php
index 02c15b64..6192b1f7 100644
--- a/framework/Collections/TPagedDataSource.php
+++ b/framework/Collections/TPagedDataSource.php
@@ -152,7 +152,7 @@ class TPagedDataSource extends TComponent implements IteratorAggregate
/**
* @return integer user-assigned number of items in data source Defaults to 0.
*/
- public function getVirtualCount()
+ public function getVirtualItemCount()
{
return $this->_virtualCount;
}
@@ -160,12 +160,12 @@ class TPagedDataSource extends TComponent implements IteratorAggregate
/**
* @param integer user-assigned number of items in data source
*/
- public function setVirtualCount($value)
+ public function setVirtualItemCount($value)
{
if(($value=TPropertyValue::ensureInteger($value))>=0)
$this->_virtualCount=$value;
else
- throw new TInvalidDataValueException('pageddatasource_virtualcount_invalid');
+ throw new TInvalidDataValueException('pageddatasource_virtualitemcount_invalid');
}
/**
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index b0dafb5d..57d00ac8 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -79,7 +79,7 @@ Prado::using('System.Web.UI.WebControls.TTable');
* datasource. The number of pages <b>PageCount</b> is calculated based the item number and the
* <b>PageSize</b> property. The datagrid will manage which section of the data source to be displayed
* based on the <b>CurrentPageIndex</b> property.
- * The second approach calculates the page number based on the <b>VirtualCount</b> property and
+ * The second approach calculates the page number based on the <b>VirtualItemCount</b> property and
* the <b>PageSize</b> property. The datagrid will always display from the beginning of the datasource
* upto the number of <b>PageSize> data items. This approach is especially useful when the datasource may
* contain too many data items to be managed by the datagrid efficiently.
@@ -504,19 +504,19 @@ class TDataGrid extends TBaseDataList implements INamingContainer
/**
* @return integer virtual number of items in the grid. Defaults to 0, meaning not set.
*/
- public function getVirtualCount()
+ public function getVirtualItemCount()
{
- return $this->getViewState('VirtualCount',0);
+ return $this->getViewState('VirtualItemCount',0);
}
/**
* @param integer virtual number of items in the grid
*/
- public function setVirtualCount($value)
+ public function setVirtualItemCount($value)
{
if(($value=TPropertyValue::ensureInteger($value))<0)
- throw new TInvalidDataValueException('datagrid_virtualcount_invalid');
- $this->setViewState('VirtualCount',$value,0);
+ throw new TInvalidDataValueException('datagrid_virtualitemcount_invalid');
+ $this->setViewState('VirtualItemCount',$value,0);
}
/**
@@ -794,7 +794,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer
$ds->setPageSize($this->getPageSize());
$ds->setAllowPaging($this->getAllowPaging());
$ds->setAllowCustomPaging($this->getAllowCustomPaging());
- $ds->setVirtualCount($this->getVirtualCount());
+ $ds->setVirtualItemCount($this->getVirtualItemCount());
return $ds;
}