From b2fba25e4b146c4896304377643e498a22a3ced0 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 2 Feb 2006 06:29:24 +0000 Subject: Added a demo of using TDataGrid with automatically generated columns. --- demos/quickstart/protected/controls/TopicList.tpl | 3 +- .../protected/pages/Controls/DataGrid1.page | 99 ++++++++++++++++++++++ .../protected/pages/Controls/DataGrid2.page | 19 +++++ .../pages/Controls/Samples/TDataGrid/Sample1.page | 10 +-- .../pages/Controls/Samples/TDataGrid/Sample1.php | 34 ++++++-- 5 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 demos/quickstart/protected/pages/Controls/DataGrid1.page create mode 100644 demos/quickstart/protected/pages/Controls/DataGrid2.page (limited to 'demos') diff --git a/demos/quickstart/protected/controls/TopicList.tpl b/demos/quickstart/protected/controls/TopicList.tpl index 79d3cd1d..550ff86e 100644 --- a/demos/quickstart/protected/controls/TopicList.tpl +++ b/demos/quickstart/protected/controls/TopicList.tpl @@ -45,7 +45,8 @@
  • Validation Controls
  • TRepeater
  • TDataList
  • -
  • TDataGrid
  • +
  • TDataGrid: Part I
  • +
  • TDataGrid: Part II
  • Active Controls
  • Creating New Controls
  • diff --git a/demos/quickstart/protected/pages/Controls/DataGrid1.page b/demos/quickstart/protected/pages/Controls/DataGrid1.page new file mode 100644 index 00000000..63f46754 --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/DataGrid1.page @@ -0,0 +1,99 @@ + + +

    TDataGrid : Part I

    + +

    +TDatagrid is an important control in building complex Web applications. It displays data in a tabular format with rows (also called items) and columns. A row is composed by cells, while columns govern how cells should be displayed according to their association with the columns. Data specified via DataSource or DataSourceID are bound to the rows and feed contents to cells. +

    +

    +TDataGrid is highly interactive. Users can sort the data along specified columns, navigate through different pages of the data, and perform actions, such as editting and deleting, on rows of the data. +

    +

    +Rows of TDataGrid can be accessed via its Items property. A row (item) can be in one of several modes: browsing, editting and selecting, which affects how cells in the row are displayed. To change an item's mode, modify EditItemIndex or SelectedItemIndex. Note, if an item is in edit mode, then selecting this item will have no effect. +

    + +

    Columns

    +

    +Columns of a data grid determine how the associated cells are displayed. For example, cells associated with a TBoundColumn are displayed differently according to their modes. A cell is displayed as a static text if the cell is in browsing mode, a text box if it is in editting mode, and so on. +

    +

    +PRADO provides five types of columns: +

    + + +

    Item Styles

    +

    +TDataGrid defines different styles applied to its items. For example, AlternatingItemStyle is applied to alternating items (item 2, 4, 6, etc.) Through these properties, one can set CSS style fields or CSS classes for the items. +

    +

    +Item styles are applied in a hierarchical way. Styles in higher hierarchy will inherit from styles in lower hierarchy. Starting from the lowest hierarchy, the item styles include item's own style, ItemStyle, AlternatingItemStyle, SelectedItemStyle, and EditItemStyle. Therefore, if background color is set as red in ItemStyle, EditItemStyle will also have red background color, unless it is explicitly set to a different value. +

    + +

    Events

    +

    +TDataGrid provides several events to facilitate manipulation of its items, +

    + + +

    Using TDataGrid

    + +

    Automatically Generated Columns

    +

    +TDataGrid by default will create a list of columns based on the structure of the bound data. TDataGrid will read the first row of the data, extract the field names of the row, and construct a column for each field. Each column is of type TBoundColumn. +

    +

    +The following example displays a list of computer product information using a TDataGrid. Columns are automatically generated. To populate datagrid items with the data, dataBind() is invoked for the datagrid in the onLoad method of the page, +

    + +public function onLoad($param) { + parent::onLoad($param); + if(!$this->IsPostBack) { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + + + +

    Manually Specified Columns

    +

    +Using automatically generated columns gives a quick way of browsing tabular data. In real applications, however, automatically generated columns are often not enough because developers have no way configuring their properties. Manually specified columns are thus more desirable. +

    +

    +To manually specify columns, set AutoGenerateColumns to false, and specify the columns in a template like the following, +

    + +<com:TDataGrid ...> + <com:TBoundColumn DataField="name" .../> + <com:TBoundColumn DataField="price" .../> + <com:TEditCommandColumn ...> + ... +</com:TDataGrid> + +

    +Note, if AutoGenerateColumns is true and there are manually specified columns, the automatically generated columns will be displayed first. Also note, the datagrid's Columns property only contains manually specified columns. +

    + + +
    \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/DataGrid2.page b/demos/quickstart/protected/pages/Controls/DataGrid2.page new file mode 100644 index 00000000..f73f46be --- /dev/null +++ b/demos/quickstart/protected/pages/Controls/DataGrid2.page @@ -0,0 +1,19 @@ + + +

    TDataGrid : Part II

    + +

    Paging and Sorting

    + +

    Updating and Deleting

    + +

    Custom Paging

    + +

    Extending TDataGrid

    + + +

    +A common use of TDataGrid is for maintaining tabular data, including browsing, editting, deleting data items. This is enabled by the command events and various item templates of TDataGrid. The following example displays a computer product information. Users can add new products, modify or delete existing ones. In order to locate the data item for updating or deleting, DataKeys property is used. +

    + + +
    \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.page b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.page index 5c24405e..05ba4630 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.page +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.page @@ -1,14 +1,14 @@

    TDataGrid Sample 1

    +

    Automatically Generated Columns

    - + AlternatingItemStyle.BackColor="lightgreen" + />
    \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php index bf11b133..ec78006b 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php @@ -2,23 +2,39 @@ class Sample1 extends TPage { - protected function getDataSource() + protected function getData() { return array( - array('name'=>'John','age'=>'31'), - array('name'=>'Bea','age'=>'35'), - array('name'=>'Rose','age'=>'33'), - array('name'=>'Diane','age'=>'37'), - array('name'=>'Bob','age'=>'30'), + array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), ); } public function onLoad($param) { parent::onLoad($param); - $this->DataGrid->DataSource=$this->getDataSource(); - $this->DataGrid->SelectedItemIndex=2; - $this->DataGrid->dataBind(); + if(!$this->IsPostBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } } } -- cgit v1.2.3