From a9d62d90ad6b78618a8491d292d75ceced033f2b Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 15 Jan 2006 19:46:50 +0000 Subject: Added column components of datagrid. --- framework/Web/UI/WebControls/TButtonColumn.php | 208 +++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 framework/Web/UI/WebControls/TButtonColumn.php (limited to 'framework/Web/UI/WebControls/TButtonColumn.php') diff --git a/framework/Web/UI/WebControls/TButtonColumn.php b/framework/Web/UI/WebControls/TButtonColumn.php new file mode 100644 index 00000000..34b4ba51 --- /dev/null +++ b/framework/Web/UI/WebControls/TButtonColumn.php @@ -0,0 +1,208 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + */ + +/** + * TDataGridColumn class file + */ +Prado::using('System.Web.UI.WebControls.TDataGridColumn'); + +/** + * TButtonColumn class + * + * TButtonColumn contains a user-defined command button, such as Add or Remove, + * that corresponds with each row in the column. + * + * The caption of the buttons in the column is determined by Text + * and DataTextField properties. If both are present, the latter takes + * precedence. The DataTextField refers to the name of the field in datasource + * whose value will be used as the button caption. If DataTextFormatString + * is not empty, the value will be formatted before rendering. + * + * The buttons in the column can be set to display as hyperlinks or push buttons + * by setting the ButtonType property. + * The CommandName will assign its value to all button's CommandName + * property. The datagrid will capture the command event where you can write event handlers + * based on different command names. + * + * Note, the command buttons created in the column will not cause validation. + * To enable validation, please use TTemplateColumn instead. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Web.UI.WebControls + * @since 3.0 + */ +class TButtonColumn extends TDataGridColumn +{ + /** + * @return string the text caption of the button + */ + public function getText() + { + return $this->getViewState('Text',''); + } + + /** + * Sets the text caption of the button. + * @param string the text caption to be set + */ + public function setText($value) + { + $this->setViewState('Text',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the field name from the data source to bind to the button caption + */ + public function getDataTextField() + { + return $this->getViewState('DataTextField',''); + } + + /** + * @param string the field name from the data source to bind to the button caption + */ + public function setDataTextField($value) + { + $this->setViewState('DataTextField',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the formatting string used to control how the button caption will be displayed. + */ + public function getDataTextFormatString() + { + return $this->getViewState('DataTextFormatString',''); + } + + /** + * @param string the formatting string used to control how the button caption will be displayed. + */ + public function setDataTextFormatString($value) + { + $this->setViewState('DataTextFormatString',$value,''); + $this->onColumnChanged(); + } + + /** + * @return string the type of command button. Defaults to LinkButton. + */ + public function getButtonType() + { + return $this->getViewState('ButtonType','LinkButton'); + } + + /** + * @param string the type of command button, LinkButton or PushButton + */ + public function setButtonType($value) + { + $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'LinkButton','PushButton'),'LinkButton'); + $this->onColumnChanged(); + } + + /** + * @return string the command name associated with the Command event. + */ + public function getCommandName() + { + return $this->getViewState('CommandName',''); + } + + /** + * Sets the command name associated with the Command event. + * @param string the text caption to be set + */ + public function setCommandName($value) + { + $this->setViewState('CommandName',$value,''); + $this->onColumnChanged(); + } + + /** + * @return boolean whether postback event trigger by this button will cause input validation, default is true + */ + public function getCausesValidation() + { + return $this->getViewState('CausesValidation',true); + } + + /** + * @param boolean whether postback event trigger by this button will cause input validation + */ + public function setCausesValidation($value) + { + $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); + $this->onColumnChanged(); + } + + /** + * @return string the group of validators which the button causes validation upon postback + */ + public function getValidationGroup() + { + return $this->getViewState('ValidationGroup',''); + } + + /** + * @param string the group of validators which the button causes validation upon postback + */ + public function setValidationGroup($value) + { + $this->setViewState('ValidationGroup',$value,''); + $this->onColumnChanged(); + } + + /** + * Initializes the specified cell to its initial values. + * This method overrides the parent implementation. + * It creates a command button within the cell. + * @param TTableCell the cell to be initialized. + * @param integer the index to the Columns property that the cell resides in. + * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) + */ + public function initializeCell($cell,$columnIndex,$itemType) + { + parent::initializeCell($cell,$columnIndex,$itemType); + if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem') + { + if($this->getButtonType()==='LinkButton') + $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); + else + $button=Prado::createComponent('System.Web.UI.WebControls.TButton'); + $button->setText($this->getText()); + $button->setCommandName($this->getCommandName()); + $button->setCausesValidation($this->getCausesValidation()); + $button->setValidationGroup($this->getValidationGroup()); + if($this->getDataTextField()!=='') + $button->attachEventHandler('DataBinding',array($this,'dataBindColumn')); + $cell->getControls()->add($button); + } + } + + public function dataBindColumn($sender,$param) + { + if(($field=$this->getDataTextField())!=='') + { + $item=$sender->getNamingContainer(); + $data=$item->getDataItem(); + $value=$this->getDataFieldValue($data,$field); + $text=$this->formatDataValue($this->getDataTextFormatString(),$value); + if(($sender instanceof TLinkButton) || ($sender instanceof TButton)) + $sender->setText($text); + } + } +} + +?> \ No newline at end of file -- cgit v1.2.3