From 304427074ddf629fd2708b23a3fe0cd0122c05a8 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 27 Aug 2006 14:45:57 +0000 Subject: Cells in TDataGrid rows can now be accessed via the corresponding column IDs. Input controls in some datagrid columns can now be accessed in a named fashion. --- HISTORY | 2 ++ .../pages/Controls/Samples/TDataGrid/Sample3.page | 7 ++++++- .../pages/Controls/Samples/TDataGrid/Sample3.php | 16 +++++++-------- framework/Web/UI/WebControls/TBoundColumn.php | 10 +++++++++ framework/Web/UI/WebControls/TButtonColumn.php | 9 ++++++++ framework/Web/UI/WebControls/TCheckBoxColumn.php | 10 +++++++++ framework/Web/UI/WebControls/TDataGrid.php | 5 +++++ .../Web/UI/WebControls/TEditCommandColumn.php | 22 +++++++++++++++++--- framework/Web/UI/WebControls/THyperLinkColumn.php | 9 ++++++++ .../quickstart/Controls/DataGrid3TestCase.php | 24 +++++++++++----------- 10 files changed, 90 insertions(+), 24 deletions(-) diff --git a/HISTORY b/HISTORY index 652d89fe..3de56f39 100644 --- a/HISTORY +++ b/HISTORY @@ -5,6 +5,8 @@ BUG: Fixed a typo in TControl::setCustomData() (Qiang) ENH: Ticket#336 - Speed up TSqliteCache with LIMIT SQL clause (Qiang) ENH: TListControl.SelectedValues and SelectedIndices can now be set before databinding (Qiang) ENH: Upgrade Scriptaculous javascript library to 1.6.2 (Wei) +ENH: Cells in TDataGrid rows can now be accessed via the corresponding column IDs (Qiang) +ENH: Input controls in some datagrid columns can now be accessed in a named fashion (Qiang) CHG: Unify all client-side javascript event handler syntax. (Wei) CHG: Added more conditions in the requirement checker (Qiang) CHG: TControl::findControlsByType() now only returns objects of the specified type (Qiang) diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page index 2864de46..96affa4a 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page @@ -23,16 +23,19 @@ > - + @@ -70,6 +74,7 @@ ItemStyle.Font.Italic="false" /> ItemType==='EditItem') { // set column width of textboxes - $item->Cells[0]->Controls[0]->Columns=40; - $item->Cells[2]->Controls[0]->Columns=5; + $item->BookTitleColumn->TextBox->Columns=40; + $item->PriceColumn->TextBox->Columns=5; } if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem') { // add an aleart dialog to delete buttons - $item->Cells[6]->Controls[0]->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; + $item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; } } @@ -160,11 +160,11 @@ class Sample3 extends TPage $item=$param->Item; $this->updateBook( $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN - $item->Cells[0]->Controls[0]->Text, // title - $item->Cells[1]->Controls[0]->Text, // publisher - $item->Cells[2]->Controls[0]->Text, // price - $item->Cells[3]->Controls[0]->Checked, // instock - $item->Cells[4]->Rating->SelectedValue // rating + $item->BookTitleColumn->TextBox->Text, // title + $item->PublisherColumn->TextBox->Text, // publisher + $item->PriceColumn->TextBox->Text, // price + $item->InStockColumn->CheckBox->Checked, // instock + $item->RatingColumn->Rating->SelectedValue // rating ); $this->DataGrid->EditItemIndex=-1; $this->DataGrid->DataSource=$this->Data; diff --git a/framework/Web/UI/WebControls/TBoundColumn.php b/framework/Web/UI/WebControls/TBoundColumn.php index 5975ec02..26fad32b 100644 --- a/framework/Web/UI/WebControls/TBoundColumn.php +++ b/framework/Web/UI/WebControls/TBoundColumn.php @@ -26,6 +26,15 @@ Prado::using('System.Web.UI.WebControls.TDataGridColumn'); * If {@link setReadOnly ReadOnly} is false, TBoundColumn will display cells in edit mode * with textboxes. Otherwise, a static text is displayed. * + * When a datagrid row is in edit mode, the textbox control in the TBoundColumn + * can be accessed by one of the following two methods: + * + * $datagridItem->BoundColumnID->TextBox + * $datagridItem->BoundColumnID->Controls[0] + * + * The second method is possible because the textbox control created within the + * datagrid cell is the first child. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -103,6 +112,7 @@ class TBoundColumn extends TDataGridColumn { $textBox=Prado::createComponent('System.Web.UI.WebControls.TTextBox'); $cell->getControls()->add($textBox); + $cell->registerObject('TextBox',$textBox); $control=$textBox; } if(($dataField=$this->getDataField())!=='') diff --git a/framework/Web/UI/WebControls/TButtonColumn.php b/framework/Web/UI/WebControls/TButtonColumn.php index 20844f14..fdcf58d3 100644 --- a/framework/Web/UI/WebControls/TButtonColumn.php +++ b/framework/Web/UI/WebControls/TButtonColumn.php @@ -39,6 +39,14 @@ Prado::using('System.Web.UI.WebControls.TImageButton'); * The buttons' CausesValidation and ValidationGroup property values * are determined by the column's corresponding properties. * + * The buttons in the column can be accessed by one of the following two methods: + * + * $datagridItem->ButtonColumnID->Button + * $datagridItem->ButtonColumnID->Controls[0] + * + * The second method is possible because the button control created within the + * datagrid cell is the first child. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -238,6 +246,7 @@ class TButtonColumn extends TDataGridColumn if($this->getDataTextField()!=='' || ($buttonType==='ImageButton' && $this->getDataImageUrlField()!=='')) $button->attachEventHandler('OnDataBinding',array($this,'dataBindColumn')); $cell->getControls()->add($button); + $cell->registerObject('Button',$button); } } diff --git a/framework/Web/UI/WebControls/TCheckBoxColumn.php b/framework/Web/UI/WebControls/TCheckBoxColumn.php index 4df1e695..d7fac8cf 100644 --- a/framework/Web/UI/WebControls/TCheckBoxColumn.php +++ b/framework/Web/UI/WebControls/TCheckBoxColumn.php @@ -28,6 +28,15 @@ Prado::using('System.Web.UI.WebControls.TCheckBox'); * TCheckBoxColumn will display an enabled checkbox provided the cells are * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting. * + * The checkbox control in the TCheckBoxColumn can be accessed by one of + * the following two methods: + * + * $datagridItem->CheckBoxColumnID->CheckBox + * $datagridItem->CheckBoxColumnID->Controls[0] + * + * The second method is possible because the checkbox control created within the + * datagrid cell is the first child. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -87,6 +96,7 @@ class TCheckBoxColumn extends TDataGridColumn $checkBox->setEnabled(false); $cell->setHorizontalAlign('Center'); $cell->getControls()->add($checkBox); + $cell->registerObject('CheckBox',$checkBox); if($this->getDataField()!=='') $checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn')); } diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index e27f6ead..ad30ff3f 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -1075,6 +1075,11 @@ class TDataGrid extends TBaseDataList implements INamingContainer $cell=new TTableHeaderCell; else $cell=new TTableCell; + if(($id=$column->getID())!=='') + { + $cell->setID($id); + $item->registerObject($id,$cell); + } $column->initializeCell($cell,$index,$itemType); $cells->add($cell); $index++; diff --git a/framework/Web/UI/WebControls/TEditCommandColumn.php b/framework/Web/UI/WebControls/TEditCommandColumn.php index 65e389bd..c742ef11 100644 --- a/framework/Web/UI/WebControls/TEditCommandColumn.php +++ b/framework/Web/UI/WebControls/TEditCommandColumn.php @@ -38,6 +38,14 @@ Prado::using('System.Web.UI.WebControls.TDataGridColumn'); * properties affect the corresponding properties of the edit and update buttons. * The cancel button does not cause validation by default. * + * The command buttons in the column can be accessed by one of the following methods: + * + * $datagridItem->ButtonColumnID->EditButton (or UpdateButton, CancelButton) + * $datagridItem->ButtonColumnID->Controls[0] + * + * The second method is possible because the button control created within the + * datagrid cell is the first child. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -154,13 +162,21 @@ class TEditCommandColumn extends TDataGridColumn { parent::initializeCell($cell,$columnIndex,$itemType); if($itemType===TDataGrid::IT_ITEM || $itemType===TDataGrid::IT_ALTERNATINGITEM || $itemType===TDataGrid::IT_SELECTEDITEM) - $cell->getControls()->add($this->createButton('Edit',$this->getEditText(),false,'')); + { + $button=$this->createButton('Edit',$this->getEditText(),false,''); + $cell->getControls()->add($button); + $cell->registerObject('EditButton',$button); + } else if($itemType===TDataGrid::IT_EDITITEM) { $controls=$cell->getControls(); - $controls->add($this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup())); + $button=$this->createButton('Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup()); + $controls->add($button); + $cell->registerObject('UpdateButton',$button); $controls->add(' '); - $controls->add($this->createButton('Cancel',$this->getCancelText(),false,'')); + $button=$this->createButton('Cancel',$this->getCancelText(),false,''); + $controls->add($button); + $cell->registerObject('CancelButton',$button); } } diff --git a/framework/Web/UI/WebControls/THyperLinkColumn.php b/framework/Web/UI/WebControls/THyperLinkColumn.php index 9fc1e3d2..b8dbb607 100644 --- a/framework/Web/UI/WebControls/THyperLinkColumn.php +++ b/framework/Web/UI/WebControls/THyperLinkColumn.php @@ -36,6 +36,14 @@ Prado::using('System.Web.UI.WebControls.THyperLink'); * The same rule applies to {@link setNavigateUrl NavigateUrl} and * {@link setDataNavigateUrlField DataNavigateUrlField} properties. * + * The hyperlinks in the column can be accessed by one of the following two methods: + * + * $datagridItem->HyperLinkColumnID->HyperLink + * $datagridItem->HyperLinkColumnID->Controls[0] + * + * The second method is possible because the hyperlink control created within the + * datagrid cell is the first child. + * * @author Qiang Xue * @version $Revision: $ $Date: $ * @package System.Web.UI.WebControls @@ -178,6 +186,7 @@ class THyperLinkColumn extends TDataGridColumn if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='') $link->attachEventHandler('OnDataBinding',array($this,'dataBindColumn')); $cell->getControls()->add($link); + $cell->registerObject('HyperLink',$link); } } diff --git a/tests/FunctionalTests/quickstart/Controls/DataGrid3TestCase.php b/tests/FunctionalTests/quickstart/Controls/DataGrid3TestCase.php index 4f53a38e..39a5aba6 100644 --- a/tests/FunctionalTests/quickstart/Controls/DataGrid3TestCase.php +++ b/tests/FunctionalTests/quickstart/Controls/DataGrid3TestCase.php @@ -10,16 +10,16 @@ class DataGrid3TestCase extends SeleniumTestCase $this->verifyTextPresent("Design Patterns: Elements of Reusable Object-Oriented Software", ""); $this->verifyTextPresent("Addison-Wesley Professional", ""); $this->verifyTextPresent("$47.04", ""); - $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl7@checked','regexp:true|checked'); - $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl7@disabled','regexp:true|disabled'); + $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl1@checked','regexp:true|checked'); + $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl1@disabled','regexp:true|disabled'); //$this->verifyElementPresent("//img[@src='images/star5.gif']",''); // edit the 2nd row - $this->clickAndWait("id=ctl0_body_DataGrid_ctl2_ctl8", ""); - $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl7", "Design Pattern: Elements of Reusable Object-Oriented Software"); - $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl8", "Addison Wesley Professional"); - $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl9", "\$57.04"); - $this->click("//input[@name='ctl0\$body\$DataGrid\$ctl2\$ctl10']", ""); + $this->clickAndWait("id=ctl0_body_DataGrid_ctl2_ctl2", ""); + $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl1", "Design Pattern: Elements of Reusable Object-Oriented Software"); + $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl2", "Addison Wesley Professional"); + $this->type("ctl0\$body\$DataGrid\$ctl2\$ctl3", "\$57.04"); + $this->click("//input[@name='ctl0\$body\$DataGrid\$ctl2\$ctl4']", ""); $this->select("ctl0\$body\$DataGrid\$ctl2\$Rating", "label=1"); $this->clickAndWait("link=Save", ""); @@ -27,23 +27,23 @@ class DataGrid3TestCase extends SeleniumTestCase $this->verifyTextPresent("Design Pattern: Elements of Reusable Object-Oriented Software", ""); $this->verifyTextPresent("Addison Wesley Professional", ""); $this->verifyTextPresent("$57.04", ""); - $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl7@checked','regexp:false|null'); - $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl7@disabled','regexp:true|disabled'); + $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl1@checked','regexp:false|null'); + $this->verifyAttribute('ctl0_body_DataGrid_ctl2_ctl1@disabled','regexp:true|disabled'); //$this->verifyElementPresent("//img[@src='images/star1.gif']",''); // verify cancel editting the 3rd row - $this->clickAndWait("id=ctl0_body_DataGrid_ctl3_ctl8", ""); + $this->clickAndWait("id=ctl0_body_DataGrid_ctl3_ctl2", ""); $this->clickAndWait("link=Cancel", ""); $this->verifyTextPresent("Design Patterns Explained : A New Perspective on Object-Oriented Design", ""); // verify deleting - $this->clickAndWait("id=ctl0_body_DataGrid_ctl3_ctl9", ""); + $this->clickAndWait("id=ctl0_body_DataGrid_ctl3_ctl3", ""); $this->verifyConfirmation("Are you sure?"); $this->verifyTextNotPresent("Design Patterns Explained : A New Perspective on Object-Oriented Design", ""); $this->verifyTextPresent("Extreme Programming Explained : Embrace Change",''); $this->chooseCancelOnNextConfirmation(); - $this->click("id=ctl0_body_DataGrid_ctl6_ctl9", ""); + $this->click("id=ctl0_body_DataGrid_ctl6_ctl3", ""); $this->verifyConfirmation("Are you sure?"); $this->verifyTextPresent("Extreme Programming Explained : Embrace Change",''); } -- cgit v1.2.3