From 045b8b2a21873b8747fde66890b094f63c095c93 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 5 Feb 2006 06:35:32 +0000 Subject: Added a demo of TDataGrid showing custom paging. --- .../protected/pages/Controls/DataGrid2.page | 10 +++- .../pages/Controls/Samples/TDataGrid/Sample6.page | 24 ++++++++++ .../pages/Controls/Samples/TDataGrid/Sample6.php | 56 ++++++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.page create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php (limited to 'demos/quickstart/protected/pages') 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 public function pageIndexChanged($sender,$param) { @@ -40,6 +40,12 @@ The following example enables the paging functionality of the datagrid shown in

Custom Paging

+

+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. +

+

+To enable custom paging, set both AllowPaging and AllowCustomPaging to true. Notify TDataGrid the total number of data items (rows) available by setting VirtualItemCount. And respond to the OnPageIndexChanged event. In the event handler, use the NewPageIndex property of the event parameter to fetch the new page of data from data source. For MySQL database, this can be done by using LIMIT clause in an SQL select statement. +

Extending TDataGrid

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 @@ + + +

TDataGrid Sample 6

+

Custom Paging

+ + + +
\ 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 @@ +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 -- cgit v1.2.3