From c397b21f03fa535ec1c742dac1a66e315879cf10 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Sun, 5 Feb 2006 00:29:37 +0000
Subject: Added an example showing TDataGrid sort functionality.
---
.../protected/pages/Controls/DataGrid2.page | 7 +-
.../pages/Controls/Samples/TDataGrid/Sample4.page | 62 +++++++++++++++
.../pages/Controls/Samples/TDataGrid/Sample4.php | 91 ++++++++++++++++++++++
3 files changed, 159 insertions(+), 1 deletion(-)
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page
create mode 100644 demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php
(limited to 'demos/quickstart')
diff --git a/demos/quickstart/protected/pages/Controls/DataGrid2.page b/demos/quickstart/protected/pages/Controls/DataGrid2.page
index 8039a738..7f11071f 100644
--- a/demos/quickstart/protected/pages/Controls/DataGrid2.page
+++ b/demos/quickstart/protected/pages/Controls/DataGrid2.page
@@ -12,7 +12,12 @@ The following example shows how to make the previous book information table an i
Sorting
-
+
+TDataGrid supports sorting its items according to specific columns. To enable sorting, set AllowSorting to true. This will turn column headers into clickable buttons if their SortExpression property is not empty. When users click on the header buttons, an OnSortCommand event will be raised. Developers can write handlers to respond to the sort command and sort the data according to SortExpression which is specified in the corresponding column.
+
+
+The following example turns Example 2 into a sortable datagrid. Users can click on any link button displayed in the header of a column and the data will be sorted in ascending order along that column.
+
Paging
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page
new file mode 100644
index 00000000..35d6c612
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page
@@ -0,0 +1,62 @@
+
+
+TDataGrid Sample 4
+Sorting with TDataGrid
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php
new file mode 100644
index 00000000..620dfc0f
--- /dev/null
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php
@@ -0,0 +1,91 @@
+'0596007124',
+ 'title'=>'Head First Design Patterns',
+ 'publisher'=>'O\'Reilly Media, Inc.',
+ 'price'=>29.67,
+ 'instock'=>true,
+ 'rating'=>4,
+ ),
+ array(
+ 'ISBN'=>'0201633612',
+ 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software',
+ 'publisher'=>'Addison-Wesley Professional',
+ 'price'=>47.04,
+ 'instock'=>true,
+ 'rating'=>5,
+ ),
+ array(
+ 'ISBN'=>'0321247140',
+ 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design',
+ 'publisher'=>'Addison-Wesley Professional',
+ 'price'=>37.49,
+ 'instock'=>true,
+ 'rating'=>4,
+ ),
+ array(
+ 'ISBN'=>'0201485672',
+ 'title'=>'Refactoring: Improving the Design of Existing Code',
+ 'publisher'=>'Addison-Wesley Professional',
+ 'price'=>47.14,
+ 'instock'=>true,
+ 'rating'=>3,
+ ),
+ array(
+ 'ISBN'=>'0321213351',
+ 'title'=>'Refactoring to Patterns',
+ 'publisher'=>'Addison-Wesley Professional',
+ 'price'=>38.49,
+ 'instock'=>true,
+ 'rating'=>2,
+ ),
+ array(
+ 'ISBN'=>'0735619670',
+ 'title'=>'Code Complete',
+ 'publisher'=>'Microsoft Press',
+ 'price'=>32.99,
+ 'instock'=>false,
+ 'rating'=>4,
+ ),
+ array(
+ 'ISBN'=>'0321278658 ',
+ 'title'=>'Extreme Programming Explained : Embrace Change',
+ 'publisher'=>'Addison-Wesley Professional',
+ 'price'=>34.99,
+ 'instock'=>true,
+ 'rating'=>3,
+ ),
+ );
+ }
+
+ protected function sortData($data,$key)
+ {
+ $compare = create_function('$a,$b','if ($a["'.$key.'"] == $b["'.$key.'"]) {return 0;}else {return ($a["'.$key.'"] > $b["'.$key.'"]) ? 1 : -1;}');
+ usort($data,$compare) ;
+ return $data ;
+ }
+
+ public function onLoad($param)
+ {
+ parent::onLoad($param);
+ if(!$this->IsPostBack)
+ {
+ $this->DataGrid->DataSource=$this->Data;
+ $this->DataGrid->dataBind();
+ }
+ }
+
+ public function sortDataGrid($sender,$param)
+ {
+ $this->DataGrid->DataSource=$this->sortData($this->Data,$param->SortExpression);
+ $this->DataGrid->dataBind();
+ }
+}
+
+?>
\ No newline at end of file
--
cgit v1.2.3