[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TCheckBoxColumn class file 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TCheckBoxColumn.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * TDataGridColumn class file 15 */ 16 Prado::using('System.Web.UI.WebControls.TDataGridColumn'); 17 /** 18 * TCheckBox class file 19 */ 20 Prado::using('System.Web.UI.WebControls.TCheckBox'); 21 22 /** 23 * TCheckBoxColumn class 24 * 25 * TCheckBoxColumn represents a checkbox column that is bound to a field in a data source. 26 * The checked state of the checkboxes are determiend by the bound data at 27 * {@link setDataField DataField}. If {@link setReadOnly ReadOnly} is false, 28 * TCheckBoxColumn will display an enabled checkbox provided the cells are 29 * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting. 30 * 31 * The checkbox control in the TCheckBoxColumn can be accessed by one of 32 * the following two methods: 33 * <code> 34 * $datagridItem->CheckBoxColumnID->CheckBox 35 * $datagridItem->CheckBoxColumnID->Controls[0] 36 * </code> 37 * The second method is possible because the checkbox control created within the 38 * datagrid cell is the first child. 39 * 40 * @author Qiang Xue <qiang.xue@gmail.com> 41 * @version $Id: TCheckBoxColumn.php 1397 2006-09-07 07:55:53Z wei $ 42 * @package System.Web.UI.WebControls 43 * @since 3.0 44 */ 45 class TCheckBoxColumn extends TDataGridColumn 46 { 47 /** 48 * @return string the field name from the data source to bind to the column 49 */ 50 public function getDataField() 51 { 52 return $this->getViewState('DataField',''); 53 } 54 55 /** 56 * @param string the field name from the data source to bind to the column 57 */ 58 public function setDataField($value) 59 { 60 $this->setViewState('DataField',$value,''); 61 } 62 63 /** 64 * @return boolean whether the items in the column can be edited. Defaults to false. 65 */ 66 public function getReadOnly() 67 { 68 return $this->getViewState('ReadOnly',false); 69 } 70 71 /** 72 * @param boolean whether the items in the column can be edited 73 */ 74 public function setReadOnly($value) 75 { 76 $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); 77 } 78 79 /** 80 * Initializes the specified cell to its initial values. 81 * This method overrides the parent implementation. 82 * It creates a checkbox inside the cell. 83 * If the column is read-only or if the item is not in edit mode, 84 * the checkbox will be set disabled. 85 * @param TTableCell the cell to be initialized. 86 * @param integer the index to the Columns property that the cell resides in. 87 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem) 88 */ 89 public function initializeCell($cell,$columnIndex,$itemType) 90 { 91 parent::initializeCell($cell,$columnIndex,$itemType); 92 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem) 93 { 94 $checkBox=new TCheckBox; 95 if($this->getReadOnly() || $itemType!==TListItemType::EditItem) 96 $checkBox->setEnabled(false); 97 $cell->setHorizontalAlign('Center'); 98 $cell->getControls()->add($checkBox); 99 $cell->registerObject('CheckBox',$checkBox); 100 if($this->getDataField()!=='') 101 $checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn')); 102 } 103 } 104 105 /** 106 * Databinds a cell in the column. 107 * This method is invoked when datagrid performs databinding. 108 * It populates the content of the cell with the relevant data from data source. 109 */ 110 public function dataBindColumn($sender,$param) 111 { 112 $item=$sender->getNamingContainer(); 113 $data=$item->getDataItem(); 114 if(($field=$this->getDataField())!=='') 115 $value=TPropertyValue::ensureBoolean($this->getDataFieldValue($data,$field)); 116 else 117 $value=TPropertyValue::ensureBoolean($data); 118 if($sender instanceof TCheckBox) 119 $sender->setChecked($value); 120 } 121 } 122 123 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |