From 085bfc19635e6cabb3aba83ed84b0fa037d53638 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Sun, 15 Jan 2006 04:06:51 +0000
Subject:
---
framework/Web/UI/WebControls/TDataGrid.php | 1157 ++++++++++++++++++++++++++++
1 file changed, 1157 insertions(+)
create mode 100644 framework/Web/UI/WebControls/TDataGrid.php
(limited to 'framework')
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
new file mode 100644
index 00000000..23b45842
--- /dev/null
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -0,0 +1,1157 @@
+
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright © 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ */
+
+/**
+ * TDataGrid class
+ *
+ * TDataGrid represents a data bound and updatable grid control.
+ *
+ * To use TDataGrid, sets its DataSource property and invokes dataBind()
+ * afterwards. The data will be populated into the TDataGrid and saved in the Items property.
+ *
+ * Each item is associated with a row of data and will be displayed as a row in table.
+ * A data item can be at one of three states: normal, selected and edit.
+ * The state determines how the item will be displayed. For example, if an item
+ * is in edit state, it may be displayed as a table row with input text boxes instead
+ * static text as in normal state.
+ * To change the state of a data item, set either the EditItemIndex property
+ * or the SelectedItemIndex property.
+ *
+ * A datagrid is specified with a list of columns. Each column specifies how the corresponding
+ * table column will be displayed. For example, the header/footer text of that column,
+ * the cells in that column, and so on. The following column types are provided by the framework,
+ * - TBoundColumn, associated with a specific field in datasource and displays the corresponding data.
+ * - TEditCommandColumn, displaying edit/update/cancel command buttons
+ * - TButtonColumn, displaying generic command buttons that may be bound to specific field in datasource.
+ * - THyperLinkColumn, displaying a hyperlink that may be boudn to specific field in datasource.
+ * - TTemplateColumn, displaying content based on templates.
+ *
+ * There are three ways to specify columns for a datagrid.
+ *
+ * - Automatically generated based on data source. By setting AutoGenerateColumns
+ * to true, a list of columns will be automatically generated based on the schema of the data source.
+ * Each column corresponds to a column of the data.
+ * - Specified in template. For example,
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ * - Manually created in code. Columns can be manipulated via the Columns property of
+ * the datagrid. For example,
+ *
+ * $column=$datagrid->createComponent('TBoundColumn');
+ * $datagrid->Columns->add($column);
+ *
+ *
+ *
+ * Note, automatically generated columns cannot be accessed via Columns property.
+ *
+ * TDataGrid supports sorting. If the AllowSorting is set to true, a column
+ * whose SortExpression is not empty will have its header text displayed as a link button.
+ * Clicking on the link button will raise OnSortCommand event. You can respond to this event,
+ * sort the data source according to the event parameter, and then invoke databind on the datagrid.
+ *
+ * TDataGrid supports paging. If the AllowPaging is set to true, a pager will be displayed
+ * on top and/or bottom of the table. How the pager will be displayed is determined by PagerDisplay
+ * and PagerButtonCount properties. The former decides the position of the pager and latter
+ * specifies how many buttons are to be used for paging purpose. Clicking on a pager button will raise
+ * an OnPageCommand event. You can respond to this event, specify the page to be displayed by
+ * setting CurrentPageIndex property, and then invoke databind on the datagrid.
+ *
+ * TDataGrid supports two kinds of paging. The first one is based on the number of data items in
+ * datasource. The number of pages PageCount is calculated based the item number and the
+ * PageSize property. The datagrid will manage which section of the data source to be displayed
+ * based on the CurrentPageIndex property.
+ * The second approach calculates the page number based on the VirtualItemCount property and
+ * the PageSize property. The datagrid will always display from the beginning of the datasource
+ * upto the number of PageSize> data items. This approach is especially useful when the datasource may
+ * contain too many data items to be managed by the datagrid efficiently.
+ *
+ * When the datagrid contains a button control that raises an OnCommand
+ * event, the event will be bubbled up to the datagrid control.
+ * If the event's command name is recognizable by the datagrid control,
+ * a corresponding item event will be raised. The following item events will be
+ * raised upon a specific command:
+ * - OnEditCommand, edit
+ * - OnCancelCommand, cancel
+ * - OnSelectCommand, select
+ * - OnDeleteCommand, delete
+ * - OnUpdateCommand, update
+ * - OnPageCommand, page
+ * - OnSortCommand, sort
+ * The data list will always raise an OnItemCommand
+ * upon its receiving a bubbled OnCommand event.
+ *
+ * An OnItemCreated event will be raised right after each item is created in the datagrid.
+ *
+ * Namespace: System.Web.UI.WebControls
+ *
+ * Properties
+ * - Items, TDataGridItemCollection, read-only
+ *
Gets the list of TDataGridItem controls that correspond to each data item.
+ * - Columns, TCollection, read-only
+ *
Gets the list of TDataGridColumn controls that are manually specified or created.
+ * - AutoGenerateColumns, boolean, default=true, kept in viewstate
+ *
Gets or sets the value indicating whether columns should be generated automatically based on the data in datasource.
+ * - AllowSorting, boolean, default=false, kept in viewstate
+ *
Gets or sets the value indicating whether sorting should be enabled.
+ * - AllowPaging, boolean, default=false, kept in viewstate
+ *
Gets or sets the value indicating whether paging should be enabled.
+ * - AllowCustomPaging, boolean, default=false, kept in viewstate
+ *
Gets or sets the value indicating whether custom paging should be enabled.
+ * - CurrentPageIndex, integer, default=0, stored in viewstate
+ *
Gets or sets the index for the page to be displayed
+ * - PageSize, integer, default=10, stored in viewstate
+ *
Gets or sets the number of data items to be displayed in each page.
+ * - PageCount, integer, read-only
+ *
Gets the number of pages to be displayed.
+ * - VirtualItemCount, integer, default=0, stored in viewstate
+ *
Gets or sets the number of data items available for paging purpose when custom paging is enabled.
+ * - PagerButtonCount, integer, default=10, stored in viewstate
+ *
Gets or sets the number of buttons to be displayed in pager for navigating among pages.
+ * - PagerDisplay, string (None,Top,Bottom,TopAndBottom), default=Bottom, stored in viewstate
+ *
Gets or sets where the pager should be displayed.
+ * - EditItemIndex, integer, default=-1, stored in viewstate
+ *
Gets or sets the index for edit item.
+ * - EditItem, TDataGridItem, read-only
+ *
Gets the edit item, null if none
+ * - EditItemStyle, string, stored in viewstate
+ *
Gets or sets the css style for the edit item
+ * - EditItemCssClass, string, stored in viewstate
+ *
Gets or sets the css classs for the edit item
+ * - SelectedItemIndex, integer, default=-1, stored in viewstate
+ *
Gets or sets the index for selected item.
+ * - SelectedItem, TDataGridItem, read-only
+ *
Gets the selected item, null if none
+ * - SelectedItemStyle, string, stored in viewstate
+ *
Gets or sets the css style for the selected item
+ * - SelectedItemCssClass, string, stored in viewstate
+ *
Gets or sets the css class for the selected item
+ * - ItemStyle, string, stored in viewstate
+ *
Gets or sets the css style for each item
+ * - ItemCssClass, string, stored in viewstate
+ *
Gets or sets the css class for each item
+ * - AlternatingItemStyle, string, stored in viewstate
+ *
Gets or sets the css style for each alternating item
+ * - AlternatingItemCssClass, string, stored in viewstate
+ *
Gets or sets the css class for each alternating item
+ * - HeaderStyle, string, stored in viewstate
+ *
Gets or sets the css style for the header
+ * - HeaderCssClass, string, stored in viewstate
+ *
Gets or sets the css class for the header
+ * - FooterStyle, string, stored in viewstate
+ *
Gets or sets the css style for the footer
+ * - FooterCssClass, string, stored in viewstate
+ *
Gets or sets the css class for the footer
+ * - PagerStyle, string, stored in viewstate
+ *
Gets or sets the css style for the pager
+ * - PagerCssClass, string, stored in viewstate
+ *
Gets or sets the css class for the pager
+ * - ShowHeader, boolean, default=true, stored in viewstate
+ *
Gets or sets the value whether to show header
+ * - ShowFooter, boolean, default=true, stored in viewstate
+ *
Gets or sets the value whether to show footer
+ * - Header, TDataGridItem
+ *
Gets the header of the data grid.
+ * - Footer, TDataGridItem
+ *
Gets the footer of the data grid.
+ * - Pager, TDataGridItem
+ *
Gets the pager of the data grid.
+ * - BackImageUrl, string, kept in viewstate
+ *
Gets or sets the URL of the background image to display behind the datagrid.
+ *
+ * Events
+ * - OnEditCommand, raised when a button control raises an OnCommand event with 'edit' command.
+ * - OnSelectCommand, raised when a button control raises an OnCommand event with 'select' command.
+ * - OnUpdateCommand, raised when a button control raises an OnCommand event with 'update' command.
+ * - OnCancelCommand, raised when a button control raises an OnCommand event with 'cancel' command.
+ * - OnDeleteCommand, raised when a button control raises an OnCommand event with 'delete' command.
+ * - OnPageCommand, raised when a button control raises an OnCommand event with 'page' command.
+ * - OnSortCommand, raised when a button control raises an OnCommand event with 'sort' command.
+ * - OnItemCommand, raised when a button control raises an OnCommand event.
+ * - OnItemCreatedCommand, raised right after an item is created.
+ *
+ * @author Qiang Xue
+ * @version $Revision: 1.25 $ $Date: 2005/12/17 06:11:28 $
+ * @package System.Web.UI.WebControls
+ */
+class TDataGrid extends TBaseDataList
+{
+ private $_columns=null;
+ private $_autoColumns=null;
+ private $_items=null;
+ private $_header=null;
+ private $_footer=null;
+ private $_pager=null;
+ private $_pagedDataSource=null;
+
+ /**
+ * @return string tag name of the datagrid
+ */
+ protected function getTagName()
+ {
+ return 'table';
+ }
+
+ public function getColumns()
+ {
+ if(!$this->_columns)
+ $this->_columns=new TDataGridColumnCollection;
+ return $this->_columns;
+ }
+
+ public function getItems()
+ {
+ if(!$this->_items)
+ $this->_items=new TDataGridItemCollection;
+ return $this->_items;
+ }
+
+ /**
+ * Creates a style object for the control.
+ * This method creates a {@link TTableStyle} to be used by datagrid.
+ * @return TStyle control style to be used
+ */
+ protected function createStyle()
+ {
+ return new TTableStyle;
+ }
+
+ /**
+ * @return string the URL of the background image for the datagrid
+ */
+ public function getBackImageUrl()
+ {
+ return $this->getStyle()->getBackImageUrl();
+ }
+
+ /**
+ * Sets the URL of the background image for the datagrid
+ * @param string the URL
+ */
+ public function setBackImageUrl($value)
+ {
+ $this->getStyle()->setBackImageUrl($value);
+ }
+
+ /**
+ * @return TTableItemStyle the style for each alternating item
+ */
+ public function getAlternatingItemStyle()
+ {
+ if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('AlternatingItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for item
+ */
+ public function getItemStyle()
+ {
+ if(($style=$this->getViewState('ItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('ItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for selected item
+ */
+ public function getSelectedItemStyle()
+ {
+ if(($style=$this->getViewState('SelectedItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('SelectedItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for edit item
+ */
+ public function getEditItemStyle()
+ {
+ if(($style=$this->getViewState('EditItemStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('EditItemStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TTableItemStyle the style for header
+ */
+ public function getHeaderStyle()
+ {
+ if(($style=$this->getViewState('HeaderStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('HeaderStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TDataGridItem the header item
+ */
+ public function getHeader()
+ {
+ return $this->_header;
+ }
+
+ /**
+ * @return TTableItemStyle the style for footer
+ */
+ public function getFooterStyle()
+ {
+ if(($style=$this->getViewState('FooterStyle',null))===null)
+ {
+ $style=new TTableItemStyle;
+ $this->setViewState('FooterStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TDataGridItem the footer item
+ */
+ public function getFooter()
+ {
+ return $this->_footer;
+ }
+
+ /**
+ * @return TDataGridPagerStyle the style for pager
+ */
+ public function getPagerStyle()
+ {
+ if(($style=$this->getViewState('PagerStyle',null))===null)
+ {
+ $style=new TDataGridPagerStyle;
+ $this->setViewState('PagerStyle',$style,null);
+ }
+ return $style;
+ }
+
+ /**
+ * @return TDataGridItem the pager
+ */
+ public function getPager()
+ {
+ return $this->_pager;
+ }
+
+ /**
+ * @return TDataGridItem the selected item, null if no item is selected.
+ */
+ public function getSelectedItem()
+ {
+ $index=$this->getSelectedItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return integer the zero-based index of the selected item in {@link getItems Items}.
+ * A value -1 means no item selected.
+ */
+ public function getSelectedItemIndex()
+ {
+ return $this->getViewState('SelectedItemIndex',-1);
+ }
+
+ /**
+ * Selects an item by its index in {@link getItems Items}.
+ * Previously selected item will be un-selected.
+ * If the item to be selected is already in edit mode, it will remain in edit mode.
+ * If the index is less than 0, any existing selection will be cleared up.
+ * @param integer the selected item index
+ */
+ public function setSelectedItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getSelectedItemIndex())!==$value)
+ {
+ $this->setViewState('SelectedItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ {
+ $item=$items->itemAt($current);
+ if($item->getItemType()!=='EditItem')
+ $item->setItemType($current%2?'AlternatingItem':'Item');
+ }
+ if($value>=0 && $value<$itemCount)
+ {
+ $item=$items->itemAt($value);
+ if($item->getItemType()!=='EditItem')
+ $item->setItemType('SelectedItem');
+ }
+ }
+ }
+
+ /**
+ * @return TDataGridItem the edit item
+ */
+ public function getEditItem()
+ {
+ $index=$this->getEditItemIndex();
+ $items=$this->getItems();
+ if($index>=0 && $index<$items->getCount())
+ return $items->itemAt($index);
+ else
+ return null;
+ }
+
+ /**
+ * @return integer the zero-based index of the edit item in {@link getItems Items}.
+ * A value -1 means no item is in edit mode.
+ */
+ public function getEditItemIndex()
+ {
+ return $this->getViewState('EditItemIndex',-1);
+ }
+
+ /**
+ * Edits an item by its index in {@link getItems Items}.
+ * Previously editting item will change to normal item state.
+ * If the index is less than 0, any existing edit item will be cleared up.
+ * @param integer the edit item index
+ */
+ public function setEditItemIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ $value=-1;
+ if(($current=$this->getEditItemIndex())!==$value)
+ {
+ $this->setViewState('EditItemIndex',$value,-1);
+ $items=$this->getItems();
+ $itemCount=$items->getCount();
+ if($current>=0 && $current<$itemCount)
+ $items->itemAt($current)->setItemType($current%2?'AlternatingItem':'Item');
+ if($value>=0 && $value<$itemCount)
+ $items->itemAt($value)->setItemType('EditItem');
+ }
+ }
+
+ /**
+ * @return boolean whether the custom paging is enabled Defaults to false.
+ */
+ public function getAllowCustomPaging()
+ {
+ return $this->getViewState('AllowCustomPaging',false);
+ }
+
+ /**
+ * @param boolean whether the custom paging is enabled
+ */
+ public function setAllowCustomPaging($value)
+ {
+ $this->setViewState('AllowCustomPaging',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether paging is enabled. Defaults to false.
+ */
+ public function getAllowPaging()
+ {
+ return $this->getViewState('AllowPaging',false);
+ }
+
+ /**
+ * @param boolean whether paging is enabled
+ */
+ public function setAllowPaging($value)
+ {
+ $this->setViewState('AllowPaging',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether sorting is enabled. Defaults to false.
+ */
+ public function getAllowSorting()
+ {
+ return $this->getViewState('AllowSorting',false);
+ }
+
+ /**
+ * @param boolean whether sorting is enabled
+ */
+ public function setAllowSorting($value)
+ {
+ $this->setViewState('AllowSorting',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return boolean whether datagrid columns should be automatically generated Defaults to false.
+ */
+ public function getAutoGenerateColumns()
+ {
+ return $this->getViewState('AutoGenerateColumns',false);
+ }
+
+ /**
+ * @param boolean whether datagrid columns should be automatically generated
+ */
+ public function setAutoGenerateColumns($value)
+ {
+ $this->setViewState('AutoGenerateColumns',TPropertyValue::ensureBoolean($value),false);
+ }
+
+ /**
+ * @return integer the index of the current page. Defaults to 0.
+ */
+ public function getCurrentPageIndex()
+ {
+ return $this->getViewState('CurrentPageIndex',0);
+ }
+
+ /**
+ * @param integer the index of the current page
+ */
+ public function setCurrentPageIndex($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
+ $this->setViewState('CurrentPageIndex',$value,0);
+ }
+
+ /**
+ * @return integer the number of rows displayed within a page. Defaults to 10.
+ */
+ public function getPageSize()
+ {
+ return $this->getViewState('PageSize',10);
+ }
+
+ /**
+ * @param integer the number of rows displayed within a page
+ */
+ public function setPageSize($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<1)
+ throw new TInvalidDataValueException('datagrid_pagesize_invalid');
+ $this->setViewState('PageSize',TPropertyValue::ensureInteger($value),10);
+ }
+
+
+ public function getPageCount()
+ {
+ if($this->_pagedDataSource)
+ return $this->_pagedDataSource->getPageCount();
+ return $this->getViewState('PageCount',0);
+ }
+
+ /**
+ * @return integer virtual number of items in the grid. Defaults to 0, meaning not set.
+ */
+ public function getVirtualItemCount()
+ {
+ return $this->getViewState('VirtualItemCount',0);
+ }
+
+ /**
+ * @param integer virtual number of items in the grid
+ */
+ public function setVirtualItemCount($value)
+ {
+ if(($value=TPropertyValue::ensureInteger($value))<0)
+ throw new TInvalidDataValueException('datagrid_virtualitemcount_invalid');
+ $this->setViewState('VirtualItemCount',$value,0);
+ }
+
+ /**
+ * @return boolean whether the header should be displayed Defaults to true.
+ */
+ public function getShowHeader()
+ {
+ return $this->getViewState('ShowHeader',true);
+ }
+
+ /**
+ * @param boolean whether the header should be displayed
+ */
+ public function setShowHeader($value)
+ {
+ $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * @return boolean whether the footer should be displayed Defaults to true.
+ */
+ public function getShowFooter()
+ {
+ return $this->getViewState('ShowFooter',true);
+ }
+
+ /**
+ * @param boolean whether the footer should be displayed
+ */
+ public function setShowFooter($value)
+ {
+ $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),true);
+ }
+
+ /**
+ * Handles BubbleEvent.
+ * This method overrides parent's implementation to handle
+ * {@link onItemCommand ItemCommand} event which is bubbled from
+ * {@link TDataGridItem} child controls.
+ * If the event parameter is {@link TDataGridCommandEventParameter} and
+ * the command name is a recognized one, which includes 'select', 'edit',
+ * 'delete', 'update', and 'cancel' (case-insensitive), then a
+ * corresponding command event is also raised (such as {@link onEditCommand EditCommand}).
+ * This method should only be used by control developers.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ protected function onBubbleEvent($sender,$param)
+ {
+ if($param instanceof TDataGridCommandEventParameter)
+ {
+ $this->onItemCommand($param);
+ $command=$param->getCommandName();
+ if(strcasecmp($command,'select')===0)
+ {
+ $this->setSelectedIndex($param->getItem()->getItemIndex());
+ $this->onSelectedIndexChanged(null);
+ return true;
+ }
+ else if(strcasecmp($command,'edit')===0)
+ {
+ $this->onEditCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,'delete')===0)
+ {
+ $this->onDeleteCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,'update')===0)
+ {
+ $this->onUpdateCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,'cancel')===0)
+ {
+ $this->onCancelCommand($param);
+ return true;
+ }
+ else if(strcasecmp($command,'sort')===0)
+ {
+ $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param->getCommandParameter()));
+ return true;
+ }
+ else if(strcasecmp($command,'page')===0)
+ {
+ $p=$param->getCommandParameter();
+ if(strcasecmp($p,'next'))
+ $pageIndex=$this->getCurrentPageIndex()+1;
+ else if(strcasecmp($p,'prev'))
+ $pageIndex=$this->getCurrentPageIndex()-1;
+ else
+ $pageIndex=TPropertyValue::ensureInteger($p)-1;
+ $this->onPageIndexChanged(new TDataGridPageChangedEventParameter($sender,$pageIndex));
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Raises CancelCommand event.
+ * This method is invoked when a button control raisesCommand event
+ * withcancel command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onCancelCommand($param)
+ {
+ $this->raiseEvent('CancelCommand',$this,$param);
+ }
+
+ /**
+ * Raises DeleteCommand event.
+ * This method is invoked when a button control raises Command event
+ * with delete command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onDeleteCommand($param)
+ {
+ $this->raiseEvent('DeleteCommand',$this,$param);
+ }
+
+ /**
+ * Raises EditCommand event.
+ * This method is invoked when a button control raises Command event
+ * with edit command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onEditCommand($param)
+ {
+ $this->raiseEvent('EditCommand',$this,$param);
+ }
+
+ /**
+ * Raises ItemCommand event.
+ * This method is invoked when a button control raises Command event.
+ * @param TDataGridItemCommandEventParameter event parameter
+ */
+ public function onItemCommand($param)
+ {
+ $this->raiseEvent('ItemCommand',$this,$param);
+ }
+
+ /**
+ * Raises SortCommand event.
+ * This method is invoked when a button control raises Command event
+ * with sort command name.
+ * @param TDataGridSortCommandEventParameter event parameter
+ */
+ public function onSortCommand($param)
+ {
+ $this->raiseEvent('SortCommand',$this,$param);
+ }
+
+ /**
+ * Raises UpdateCommand event.
+ * This method is invoked when a button control raises Command event
+ * with update command name.
+ * @param TDataGridCommandEventParameter event parameter
+ */
+ public function onUpdateCommand($param)
+ {
+ $this->raiseEvent('UpdateCommand',$this,$param);
+ }
+
+ /**
+ * Raises ItemCreated event.
+ * This method is invoked right after a datagrid item is created and before
+ * added to page hierarchy.
+ * @param TDataGridItemEventParameter event parameter
+ */
+ public function onItemCreated($param)
+ {
+ $this->raiseEvent('ItemCreated',$this,$param);
+ }
+
+ /**
+ * Raises ItemDataBound event.
+ * This method is invoked for each datagrid item after it performs
+ * databinding.
+ * @param TDataGridItemEventParameter event parameter
+ */
+ public function onItemDataBound($param)
+ {
+ $this->raiseEvent('ItemDataBound',$this,$param);
+ }
+
+ /**
+ * Raises PageIndexChanged event.
+ * This method is invoked when current page is changed.
+ * @param TDataGridPageChangedEventParameter event parameter
+ */
+ public function onPageIndexChanged($param)
+ {
+ $this->raiseEvent('PageIndexChanged',$this,$param);
+ }
+}
+/**
+ * TDataGridItemEventParameter class
+ *
+ * TDataGridItemEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onItemCreated ItemCreated} event of {@link TDataGrid} controls.
+ * The {@link getItem Item} property indicates the DataList item related with the event.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItemEventParameter extends TEventParameter
+{
+ /**
+ * The TDataGridItem control responsible for the event.
+ * @var TDataGridItem
+ */
+ private $_item=null;
+
+ /**
+ * Constructor.
+ * @param TDataGridItem DataList item related with the corresponding event
+ */
+ public function __construct(TDataGridItem $item)
+ {
+ $this->_item=$item;
+ }
+
+ /**
+ * @return TDataGridItem DataList item related with the corresponding event
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+}
+
+/**
+ * TDataGridCommandEventParameter class
+ *
+ * TDataGridCommandEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onItemCommand ItemCommand} event of {@link TDataGrid} controls.
+ *
+ * The {@link getItem Item} property indicates the DataList item related with the event.
+ * The {@link getCommandSource CommandSource} refers to the control that originally
+ * raises the Command event.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridCommandEventParameter extends TCommandEventParameter
+{
+ /**
+ * @var TDataGridItem the TDataGridItem control responsible for the event.
+ */
+ private $_item=null;
+ /**
+ * @var TControl the control originally raises the Command event.
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TDataGridItem DataList item responsible for the event
+ * @param TControl original event sender
+ * @param TCommandEventParameter original event parameter
+ */
+ public function __construct($item,$source,TCommandEventParameter $param)
+ {
+ $this->_item=$item;
+ $this->_source=$source;
+ parent::__construct($param->getCommandName(),$param->getCommandParameter());
+ }
+
+ /**
+ * @return TDataGridItem the TDataGridItem control responsible for the event.
+ */
+ public function getItem()
+ {
+ return $this->_item;
+ }
+
+ /**
+ * @return TControl the control originally raises the Command event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+}
+
+/**
+ * TDataGridSortCommandEventParameter class
+ *
+ * TDataGridSortCommandEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onSortCommand SortCommand} event of {@link TDataGrid} controls.
+ *
+ * The {@link getCommandSource CommandSource} property refers to the control
+ * that originally raises the Command event, while {@link getSortExpression SortExpression}
+ * gives the sort expression carried with the sort command.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridSortCommandEventParameter extends TEventParameter
+{
+ /**
+ * @var string sort expression
+ */
+ private $_sortExpression='';
+ /**
+ * @var TControl original event sender
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl the control originally raises the Command event.
+ * @param TDataGridCommandEventParameter command event parameter
+ */
+ public function __construct($source,TDataGridCommandEventParameter $param)
+ {
+ $this->_source=$source;
+ $this->_sortExpression=$param->getCommandParameter();
+ }
+
+ /**
+ * @return TControl the control originally raises the Command event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * @return string sort expression
+ */
+ public function getSortExpression()
+ {
+ return $this->_sortExpression;
+ }
+}
+
+/**
+ * TDataGridPageChangedEventParameter class
+ *
+ * TDataGridPageChangedEventParameter encapsulates the parameter data for
+ * {@link TDataGrid::onPageIndexChanged PageIndexChanged} event of {@link TDataGrid} controls.
+ *
+ * The {@link getCommandSource CommandSource} property refers to the control
+ * that originally raises the Command event, while {@link getNewPageIndex NewPageIndex}
+ * returns the new page index carried with the page command.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridPageChangedEventParameter extends TEventParameter
+{
+ /**
+ * @var integer new page index
+ */
+ private $_newIndex;
+ /**
+ * @var TControl original event sender
+ */
+ private $_source=null;
+
+ /**
+ * Constructor.
+ * @param TControl the control originally raises the Command event.
+ * @param integer new page index
+ */
+ public function __construct($source,$newPageIndex)
+ {
+ $this->_source=$source;
+ $this->_newIndex=$newPageIndex;
+ }
+
+ /**
+ * @return TControl the control originally raises the Command event.
+ */
+ public function getCommandSource()
+ {
+ return $this->_source;
+ }
+
+ /**
+ * @return integer new page index
+ */
+ public function getNewPageIndex()
+ {
+ return $this->_newIndex;
+ }
+}
+
+/**
+ * TDataGridItem class
+ *
+ * A TDataGridItem control represents an item in the {@link TDataGrid} control,
+ * such as heading section, footer section, or a data item.
+ * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
+ * and {@link getDataItem DataItem} properties, respectively. The type of the item
+ * is given by {@link getItemType ItemType} property. Property {@link getDataSetIndex DataSetIndex}
+ * gives the index of the item from the bound data source.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItem extends TTableRow implements INamingContainer
+{
+ /**
+ * @var integer index of the data item in the Items collection of DataList
+ */
+ private $_itemIndex='';
+ /**
+ * @var integer index of the item from the bound data source
+ */
+ private $_dataSetIndex=0;
+ /**
+ * type of the TDataGridItem
+ * @var string
+ */
+ private $_itemType='';
+ /**
+ * value of the data item
+ * @var mixed
+ */
+ private $_dataItem=null;
+
+ /**
+ * Constructor.
+ * @param integer zero-based index of the item in the item collection of DataList
+ * @param string item type, can be 'Header','Footer','Item','AlternatingItem','SelectedItem','EditItem','Separator','Pager'.
+ */
+ public function __construct($itemIndex,$dataSetIndex,$itemType)
+ {
+ $this->_itemIndex=$itemIndex;
+ $this->_dataSetIndex=$dataSetIndex;
+ $this->setItemType($itemType);
+ }
+
+ /**
+ * @return string item type, can be 'Header','Footer','Item','AlternatingItem','SelectedItem','EditItem','Separator','Pager'
+ */
+ public function getItemType()
+ {
+ return $this->_itemType;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ */
+ public function setItemType($value)
+ {
+ $this->_itemType=TPropertyValue::ensureEnum($value,'Header','Footer','Item','AlternatingItem','SelectedItem','EditItem','Separator','Pager');
+ }
+
+ /**
+ * @return integer zero-based index of the item in the item collection of DataList
+ */
+ public function getItemIndex()
+ {
+ return $this->_itemIndex;
+ }
+
+ /**
+ * @return integer the index of the datagrid item from the bound data source
+ */
+ public function getDataSetIndex()
+ {
+ return $this->_dataSetIndex;
+ }
+
+ /**
+ * @return mixed data associated with the item
+ */
+ public function getDataItem()
+ {
+ return $this->_dataItem;
+ }
+
+ /**
+ * @param mixed data to be associated with the item
+ */
+ public function setDataItem($value)
+ {
+ $this->_dataItem=$value;
+ }
+
+ /**
+ * Handles BubbleEvent.
+ * This method overrides parent's implementation by wrapping event parameter
+ * for Command event with item information.
+ * @param TControl the sender of the event
+ * @param TEventParameter event parameter
+ * @return boolean whether the event bubbling should stop here.
+ */
+ protected function onBubbleEvent($sender,$param)
+ {
+ if($param instanceof TCommandEventParameter)
+ {
+ $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
+ return true;
+ }
+ else
+ return false;
+ }
+}
+
+
+/**
+ * TDataGridItemCollection class.
+ *
+ * TDataGridItemCollection represents a collection of data grid items.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridItemCollection extends TList
+{
+ /**
+ * Returns true only when the item to be added is a {@link TDataGridItem}.
+ * This method is invoked before adding an item to the list.
+ * If it returns true, the item will be added to the list, otherwise not.
+ * @param mixed item to be added
+ * @return boolean whether the item can be added to the list
+ */
+ protected function canAddItem($item)
+ {
+ return ($item instanceof TDataGridItem);
+ }
+}
+
+/**
+ * TDataGridColumnCollection class.
+ *
+ * TDataGridColumnCollection represents a collection of data grid columns.
+ *
+ * @author Qiang Xue
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TDataGridColumnCollection extends TList
+{
+ /**
+ * Returns true only when the item to be added is a {@link TDataGridItem}.
+ * This method is invoked before adding an item to the list.
+ * If it returns true, the item will be added to the list, otherwise not.
+ * @param mixed item to be added
+ * @return boolean whether the item can be added to the list
+ */
+ protected function canAddItem($item)
+ {
+ return ($item instanceof TDataGridColumn);
+ }
+}
+
+
+class TDataGridPagerStyle extends TTableItemStyle
+{
+}
+
+?>
\ No newline at end of file
--
cgit v1.2.3