summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-02-04 23:56:29 +0000
committerxue <>2006-02-04 23:56:29 +0000
commit139ca38ddcf4998c882cfc98cb932524de210d86 (patch)
tree99471fff9e2db46d01e5473cfd5c1566c7c1209a
parent97d5ad831a6003418562b7f44e9a08e562d88a0c (diff)
Modified TDataGrid sample to enable updating rating.
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page17
-rw-r--r--demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php8
-rw-r--r--framework/Web/UI/WebControls/TDataBoundControl.php3
-rw-r--r--framework/Web/UI/WebControls/TDataGrid.php106
-rw-r--r--framework/Web/UI/WebControls/TDataList.php45
-rw-r--r--framework/Web/UI/WebControls/TListControl.php2
-rw-r--r--framework/Web/UI/WebControls/TRepeater.php25
7 files changed, 104 insertions, 102 deletions
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page
index 82253c30..6d3397ee 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.page
@@ -46,6 +46,23 @@
HeaderText="In-stock"
DataField="instock"
/>
+ <com:TTemplateColumn>
+ <prop:HeaderTemplate>Rating</prop:HeaderTemplate>
+ <prop:ItemTemplate>
+ <img src="images/star<%#$this->NamingContainer->DataItem['rating']%>.gif" alt="" />
+ </prop:ItemTemplate>
+ <prop:EditItemTemplate>
+ <com:TDropDownList
+ SelectedValue=<%#$this->NamingContainer->DataItem['rating'] %>
+ ID="Rating">
+ <com:TListItem Value="1" />
+ <com:TListItem Value="2" />
+ <com:TListItem Value="3" />
+ <com:TListItem Value="4" />
+ <com:TListItem Value="5" />
+ </com:TDropDownList>
+ </prop:EditItemTemplate>
+ </com:TTemplateColumn>
<com:TEditCommandColumn
HeaderText="Edit"
HeaderStyle.Width="100px"
diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php
index 89adcc37..6d8c0085 100644
--- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php
+++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php
@@ -86,7 +86,7 @@ class Sample3 extends TPage
$this->setViewState('Data',$this->_data);
}
- protected function updateBook($isbn,$title,$publisher,$price,$instock)
+ protected function updateBook($isbn,$title,$publisher,$price,$instock,$rating)
{
// In real applications, data should be saved to database using an SQL UPDATE statement
if($this->_data===null)
@@ -101,6 +101,7 @@ class Sample3 extends TPage
$updateRow['publisher']=$publisher;
$updateRow['price']=TPropertyValue::ensureFloat(ltrim($price,'$'));
$updateRow['instock']=TPropertyValue::ensureBoolean($instock);
+ $updateRow['rating']=TPropertyValue::ensureInteger($rating);
$this->saveData();
}
}
@@ -143,7 +144,7 @@ class Sample3 extends TPage
if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem')
{
// add an aleart dialog to delete buttons
- $item->Cells[5]->Controls[0]->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;';
+ $item->Cells[6]->Controls[0]->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;';
}
}
@@ -162,7 +163,8 @@ class Sample3 extends TPage
$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[3]->Controls[0]->Checked, // instock
+ $item->Cells[4]->Rating->SelectedValue // rating
);
$this->DataGrid->EditItemIndex=-1;
$this->DataGrid->DataSource=$this->Data;
diff --git a/framework/Web/UI/WebControls/TDataBoundControl.php b/framework/Web/UI/WebControls/TDataBoundControl.php
index b7294383..0bb771bf 100644
--- a/framework/Web/UI/WebControls/TDataBoundControl.php
+++ b/framework/Web/UI/WebControls/TDataBoundControl.php
@@ -196,7 +196,8 @@ abstract class TDataBoundControl extends TWebControl
$this->dataBindProperties();
$this->onDataBinding(null);
$data=$this->getData();
- $this->performDataBinding($data);
+ if($data instanceof Traversable)
+ $this->performDataBinding($data);
$this->setIsDataBound(true);
$this->onDataBound(null);
}
diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php
index eceb498b..1817d03e 100644
--- a/framework/Web/UI/WebControls/TDataGrid.php
+++ b/framework/Web/UI/WebControls/TDataGrid.php
@@ -869,76 +869,66 @@ class TDataGrid extends TBaseDataList implements INamingContainer
$this->reset();
$keys=$this->getDataKeys();
$keys->clear();
- if($data instanceof Traversable)
+ $keyField=$this->getDataKeyField();
+ $this->_pagedDataSource=$ds=$this->createPagedDataSource();
+ $ds->setDataSource($data);
+ $allowPaging=$ds->getAllowPaging();
+ if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount())
+ throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
+ // get all columns
+ if($this->getAutoGenerateColumns())
{
- $keyField=$this->getDataKeyField();
- $this->_pagedDataSource=$ds=$this->createPagedDataSource();
- $ds->setDataSource($data);
- $allowPaging=$ds->getAllowPaging();
- if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount())
- throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
- // get all columns
- if($this->getAutoGenerateColumns())
- {
- $columns=new TList($this->getColumns());
- $autoColumns=$this->createAutoColumns($ds);
- $columns->mergeWith($autoColumns);
- }
- else
- $columns=$this->getColumns();
+ $columns=new TList($this->getColumns());
+ $autoColumns=$this->createAutoColumns($ds);
+ $columns->mergeWith($autoColumns);
+ }
+ else
+ $columns=$this->getColumns();
- $items=$this->getItems();
+ $items=$this->getItems();
- if(($columnCount=$columns->getCount())>0)
- {
- foreach($columns as $column)
- $column->initialize();
- $allowPaging=$ds->getAllowPaging();
- if($allowPaging)
- $this->createPager(-1,-1,$columnCount,$ds);
- $this->createItemInternal(-1,-1,'Header',true,null,$columns);
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- $index=0;
- $dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
- foreach($ds as $data)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($data,$keyField));
- if($index===$editIndex)
- $itemType='EditItem';
- else if($index===$selectedIndex)
- $itemType='SelectedItem';
- else if($index % 2)
- $itemType='AlternatingItem';
- else
- $itemType='Item';
- $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$data,$columns));
- $index++;
- $dsIndex++;
- }
- $this->createItemInternal(-1,-1,'Footer',true,null,$columns);
- if($allowPaging)
- $this->createPager(-1,-1,$columnCount,$ds);
- $this->setViewState('ItemCount',$index,0);
- $this->setViewState('PageCount',$ds->getPageCount(),0);
- $this->setViewState('DataSourceCount',$ds->getDataSourceCount(),0);
- }
- else
+ if(($columnCount=$columns->getCount())>0)
+ {
+ foreach($columns as $column)
+ $column->initialize();
+ $allowPaging=$ds->getAllowPaging();
+ if($allowPaging)
+ $this->createPager(-1,-1,$columnCount,$ds);
+ $this->createItemInternal(-1,-1,'Header',true,null,$columns);
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ $index=0;
+ $dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
+ foreach($ds as $data)
{
- $this->clearViewState('ItemCount');
- $this->clearViewState('PageCount');
- $this->clearViewState('DataSourceCount');
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($data,$keyField));
+ if($index===$editIndex)
+ $itemType='EditItem';
+ else if($index===$selectedIndex)
+ $itemType='SelectedItem';
+ else if($index % 2)
+ $itemType='AlternatingItem';
+ else
+ $itemType='Item';
+ $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$data,$columns));
+ $index++;
+ $dsIndex++;
}
- $this->_pagedDataSource=null;
+ $this->createItemInternal(-1,-1,'Footer',true,null,$columns);
+ if($allowPaging)
+ $this->createPager(-1,-1,$columnCount,$ds);
+ $this->setViewState('ItemCount',$index,0);
+ $this->setViewState('PageCount',$ds->getPageCount(),0);
+ $this->setViewState('DataSourceCount',$ds->getDataSourceCount(),0);
}
else
{
- $this->_pagedDataSource=null;
$this->clearViewState('ItemCount');
$this->clearViewState('PageCount');
$this->clearViewState('DataSourceCount');
}
+ $this->_pagedDataSource=null;
}
/**
diff --git a/framework/Web/UI/WebControls/TDataList.php b/framework/Web/UI/WebControls/TDataList.php
index 825bb9db..0bdeb4a4 100644
--- a/framework/Web/UI/WebControls/TDataList.php
+++ b/framework/Web/UI/WebControls/TDataList.php
@@ -1107,32 +1107,29 @@ class TDataList extends TBaseDataList implements INamingContainer, IRepeatInfoUs
$keys->clear();
$keyField=$this->getDataKeyField();
$itemIndex=0;
- if($data instanceof Traversable)
+ $items=$this->getItems();
+ $hasSeparator=$this->_separatorTemplate!==null;
+ $selectedIndex=$this->getSelectedItemIndex();
+ $editIndex=$this->getEditItemIndex();
+ foreach($data as $dataItem)
{
- $items=$this->getItems();
- $hasSeparator=$this->_separatorTemplate!==null;
- $selectedIndex=$this->getSelectedItemIndex();
- $editIndex=$this->getEditItemIndex();
- foreach($data as $dataItem)
- {
- if($keyField!=='')
- $keys->add($this->getDataFieldValue($dataItem,$keyField));
- if($itemIndex===0 && $this->_headerTemplate!==null)
- $this->_header=$this->createItemInternal(-1,'Header',true,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemInternal($itemIndex-1,'Separator',true,null);
- if($itemIndex===$editIndex)
- $itemType='EditItem';
- else if($itemIndex===$selectedIndex)
- $itemType='SelectedItem';
- else
- $itemType=$itemIndex%2?'AlternatingItem':'Item';
- $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0 && $this->_footerTemplate!==null)
- $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
+ if($keyField!=='')
+ $keys->add($this->getDataFieldValue($dataItem,$keyField));
+ if($itemIndex===0 && $this->_headerTemplate!==null)
+ $this->_header=$this->createItemInternal(-1,'Header',true,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemInternal($itemIndex-1,'Separator',true,null);
+ if($itemIndex===$editIndex)
+ $itemType='EditItem';
+ else if($itemIndex===$selectedIndex)
+ $itemType='SelectedItem';
+ else
+ $itemType=$itemIndex%2?'AlternatingItem':'Item';
+ $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
+ $itemIndex++;
}
+ if($itemIndex>0 && $this->_footerTemplate!==null)
+ $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index 00381890..169cc72c 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -151,8 +151,6 @@ abstract class TListControl extends TDataBoundControl
$items=$this->getItems();
if(!$this->getAppendDataBoundItems())
$items->clear();
- if(!($data instanceof Traversable))
- return;
$textField=$this->getDataTextField();
if($textField==='')
$textField=0;
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 65b3106e..716478b8 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -374,22 +374,19 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->reset();
$items=$this->getItems();
$itemIndex=0;
- if($data instanceof Traversable)
+ $hasSeparator=$this->_separatorTemplate!==null;
+ foreach($data as $dataItem)
{
- $hasSeparator=$this->_separatorTemplate!==null;
- foreach($data as $dataItem)
- {
- if($itemIndex===0 && $this->_headerTemplate!==null)
- $this->_header=$this->createItemInternal(-1,'Header',true,null);
- if($hasSeparator && $itemIndex>0)
- $this->createItemInternal($itemIndex-1,'Separator',true,null);
- $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
- $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
- $itemIndex++;
- }
- if($itemIndex>0 && $this->_footerTemplate!==null)
- $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
+ if($itemIndex===0 && $this->_headerTemplate!==null)
+ $this->_header=$this->createItemInternal(-1,'Header',true,null);
+ if($hasSeparator && $itemIndex>0)
+ $this->createItemInternal($itemIndex-1,'Separator',true,null);
+ $itemType=$itemIndex%2==0?'Item':'AlternatingItem';
+ $items->add($this->createItemInternal($itemIndex,$itemType,true,$dataItem));
+ $itemIndex++;
}
+ if($itemIndex>0 && $this->_footerTemplate!==null)
+ $this->_footer=$this->createItemInternal(-1,'Footer',true,null);
$this->setViewState('ItemCount',$itemIndex,0);
}