summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--demos/quickstart/protected/pages/Controls/DataGrid2.page7
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.page62
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php91
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php2
5 files changed, 162 insertions, 2 deletions
diff --git a/.gitattributes b/.gitattributes
index 539b3b89..3e1a7e86 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -126,6 +126,8 @@ demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.page -text
demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.php -text
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/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 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
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample3" />
<h2>Sorting</h2>
-
+<p>
+TDataGrid supports sorting its items according to specific columns. To enable sorting, set <tt>AllowSorting</tt> to true. This will turn column headers into clickable buttons if their <tt>SortExpression</tt> property is not empty. When users click on the header buttons, an <tt>OnSortCommand</tt> event will be raised. Developers can write handlers to respond to the sort command and sort the data according to <tt>SortExpression</tt> which is specified in the corresponding column.
+</p>
+<p>
+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.
+</p>
<com:RunBar PagePath="Controls.Samples.TDataGrid.Sample4" />
<h2>Paging</h2>
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 @@
+<com:TContent ID="body">
+
+<h1>TDataGrid Sample 4</h1>
+<h2>Sorting with TDataGrid</h2>
+
+<com:TDataGrid
+ Width="700px"
+ CellPadding="2"
+ ID="DataGrid"
+ AutoGenerateColumns="false"
+ HeaderStyle.BackColor="black"
+ HeaderStyle.ForeColor="white"
+ ItemStyle.BackColor="#BFCFFF"
+ ItemStyle.Font.Italic="true"
+ AlternatingItemStyle.BackColor="#E6ECFF"
+ AllowSorting="true"
+ OnSortCommand="sortDataGrid">
+
+ <com:THyperLinkColumn
+ SortExpression="title"
+ HeaderText="Book Title"
+ DataTextField="title"
+ DataNavigateUrlField="ISBN"
+ DataNavigateUrlFormatString="http://www.amazon.com/gp/product/%s"
+ Target="_blank"
+ />
+ <com:TBoundColumn
+ SortExpression="publisher"
+ HeaderText="Publisher"
+ DataField="publisher"
+ />
+ <com:TBoundColumn
+ SortExpression="price"
+ ItemStyle.HorizontalAlign="Right"
+ ItemStyle.Wrap="false"
+ ItemStyle.Font.Italic="false"
+ ItemStyle.ForeColor="green"
+ HeaderText="Price"
+ DataField="price"
+ DataFormatString="$%.2f"
+ />
+ <com:TCheckBoxColumn
+ SortExpression="instock"
+ HeaderText="In-stock"
+ HeaderStyle.Wrap="false"
+ DataField="instock"
+ />
+ <com:TTemplateColumn SortExpression="rating">
+ <prop:HeaderTemplate>
+ <com:TLinkButton
+ Text="Rating"
+ CommandName="Sort"
+ CommandParameter="rating"
+ CausesValidation="false" />
+ </prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <img src="images/star<%#$this->NamingContainer->DataItem['rating']%>.gif" alt="" />
+ </prop:ItemTemplate>
+ </com:TTemplateColumn>
+</com:TDataGrid>
+
+</com:TContent> \ 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 @@
+<?php
+
+class Sample4 extends TPage
+{
+ protected function getData()
+ {
+ return array(
+ array(
+ 'ISBN'=>'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
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index 1817d03e..91b0c374 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -599,7 +599,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer
}
else if(strcasecmp($command,'sort')===0)
{
- $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param->getCommandParameter()));
+ $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param));
return true;
}
else if(strcasecmp($command,'page')===0)