[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TDataGrid.php (source)

   1  <?php
   2  /**
   3   * TDataGrid related class files.
   4   * This file contains the definition of the following classes:
   5   * TDataGrid, TDataGridItem, TDataGridItemCollection, TDataGridColumnCollection,
   6   * TDataGridPagerStyle, TDataGridItemEventParameter,
   7   * TDataGridCommandEventParameter, TDataGridSortCommandEventParameter,
   8   * TDataGridPageChangedEventParameter
   9   *
  10   * @author Qiang Xue <qiang.xue@gmail.com>
  11   * @link http://www.pradosoft.com/
  12   * @copyright Copyright &copy; 2005 PradoSoft
  13   * @license http://www.pradosoft.com/license/
  14   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
  15   * @package System.Web.UI.WebControls
  16   */
  17  
  18  /**
  19   * Includes TBaseList, TPagedDataSource, TDummyDataSource and TTable classes
  20   */
  21  Prado::using('System.Web.UI.WebControls.TBaseDataList');
  22  Prado::using('System.Collections.TPagedDataSource');
  23  Prado::using('System.Collections.TDummyDataSource');
  24  Prado::using('System.Web.UI.WebControls.TTable');
  25  Prado::using('System.Web.UI.WebControls.TPanel');
  26  
  27  /**
  28   * TDataGrid class
  29   *
  30   * TDataGrid represents a data bound and updatable grid control.
  31   *
  32   * To populate data into the datagrid, sets its {@link setDataSource DataSource}
  33   * to a tabular data source and call {@link dataBind()}.
  34   * Each row of data will be represented by an item in the {@link getItems Items}
  35   * collection of the datagrid.
  36   *
  37   * An item can be at one of three states: browsing, selected and edit.
  38   * The state determines how the item will be displayed. For example, if an item
  39   * is in edit state, it may be displayed as a table row with input text boxes
  40   * if the columns are of type {@link TBoundColumn}; and if in browsing state,
  41   * they are displayed as static text.
  42   *
  43   * To change the state of an item, set {@link setEditItemIndex EditItemIndex}
  44   * or {@link setSelectedItemIndex SelectedItemIndex} property.
  45   *
  46   * Each datagrid item has a {@link TDataGridItem::getItemType type}
  47   * which tells the position and state of the item in the datalist. An item in the header
  48   * of the repeater is of type Header. A body item may be of either
  49   * Item, AlternatingItem, SelectedItem or EditItem, depending whether the item
  50   * index is odd or even, whether it is being selected or edited.
  51   *
  52   * A datagrid is specified with a list of columns. Each column specifies how the corresponding
  53   * table column will be displayed. For example, the header/footer text of that column,
  54   * the cells in that column, and so on. The following column types are currently
  55   * provided by the framework,
  56   * - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
  57   * - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
  58   * - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
  59   * - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
  60   * - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
  61   * - {@link TTemplateColumn}, displaying content based on templates.
  62   *
  63   * There are three ways to specify columns for a datagrid.
  64   * <ul>
  65   *  <li>Automatically generated based on data source.
  66   *  By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true,
  67   *  a list of columns will be automatically generated based on the schema of the data source.
  68   *  Each column corresponds to a column of the data.</li>
  69   *  <li>Specified in template. For example,
  70   *    <code>
  71   *     <com:TDataGrid ...>
  72   *        <com:TBoundColumn .../>
  73   *        <com:TEditCommandColumn .../>
  74   *     </com:TDataGrid>
  75   *    </code>
  76   *  </li>
  77   *  <li>Manually created in code. Columns can be manipulated via
  78   *  the {@link setColumns Columns} property of the datagrid. For example,
  79   *  <code>
  80   *    $column=new TBoundColumn;
  81   *    $datagrid->Columns[]=$column;
  82   *  </code>
  83   *  </li>
  84   * </ul>
  85   * Note, automatically generated columns cannot be accessed via
  86   * the {@link getColumns Columns} property.
  87   *
  88   * TDataGrid supports sorting. If the {@link setAllowSorting AllowSorting}
  89   * is set to true, a column with nonempty {@link setSortExpression SortExpression}
  90   * will have its header text displayed as a clickable link button.
  91   * Clicking on the link button will raise {@link onSortCommand OnSortCommand}
  92   * event. You can respond to this event, sort the data source according
  93   * to the event parameter, and then invoke {@link databind()} on the datagrid
  94   * to show to end users the sorted data.
  95   *
  96   * TDataGrid supports paging. If the {@link setAllowPaging AllowPaging}
  97   * is set to true, a pager will be displayed on top and/or bottom of the table.
  98   * How the pager will be displayed is determined by the {@link getPagerStyle PagerStyle}
  99   * property. Clicking on a pager button will raise an {@link onPageIndexChanged OnPageIndexChanged}
 100   * event. You can respond to this event, specify the page to be displayed by
 101   * setting {@link setCurrentPageIndex CurrentPageIndex}</b> property,
 102   * and then invoke {@link databind()} on the datagrid to show to end users
 103   * a new page of data.
 104   *
 105   * TDataGrid supports two kinds of paging. The first one is based on the number of data items in
 106   * datasource. The number of pages {@link getPageCount PageCount} is calculated based
 107   * the item number and the {@link setPageSize PageSize} property.
 108   * The datagrid will manage which section of the data source to be displayed
 109   * based on the {@link setCurrentPageIndex CurrentPageIndex} property.
 110   * The second approach calculates the page number based on the
 111   * {@link setVirtualItemCount VirtualItemCount} property and
 112   * the {@link setPageSize PageSize} property. The datagrid will always
 113   * display from the beginning of the datasource up to the number of
 114   * {@link setPageSize PageSize} data items. This approach is especially
 115   * useful when the datasource may contain too many data items to be managed by
 116   * the datagrid efficiently.
 117   *
 118   * When the datagrid contains a button control that raises an {@link onCommand OnCommand}
 119   * event, the event will be bubbled up to the datagrid control.
 120   * If the event's command name is recognizable by the datagrid control,
 121   * a corresponding item event will be raised. The following item events will be
 122   * raised upon a specific command:
 123   * - OnEditCommand, if CommandName=edit
 124   * - OnCancelCommand, if CommandName=cancel
 125   * - OnSelectCommand, if CommandName=select
 126   * - OnDeleteCommand, if CommandName=delete
 127   * - OnUpdateCommand, if CommandName=update
 128   * - onPageIndexChanged, if CommandName=page
 129   * - OnSortCommand, if CommandName=sort
 130   * Note, an {@link onItemCommand OnItemCommand} event is raised in addition to
 131   * the above specific command events.
 132   *
 133   * TDataGrid also raises an {@link onItemCreated OnItemCreated} event for
 134   * every newly created datagrid item. You can respond to this event to customize
 135   * the content or style of the newly created item.
 136   *
 137   * Note, the data bound to the datagrid are reset to null after databinding.
 138   * There are several ways to access the data associated with a datagrid row:
 139   * - Access the data in {@link onItemDataBound OnItemDataBound} event
 140   * - Use {@link getDataKeys DataKeys} to obtain the data key associated with
 141   * the specified datagrid row and use the key to fetch the corresponding data
 142   * from some persistent storage such as DB.
 143   * - Save the data in viewstate and get it back during postbacks.
 144   *
 145   * @author Qiang Xue <qiang.xue@gmail.com>
 146   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
 147   * @package System.Web.UI.WebControls
 148   * @since 3.0
 149   */
 150  class TDataGrid extends TBaseDataList implements INamingContainer
 151  {
 152      /**
 153       * datagrid item types
 154       * @deprecated deprecated since version 3.0.4. Use TListItemType constants instead.
 155       */
 156      const IT_HEADER='Header';
 157      const IT_FOOTER='Footer';
 158      const IT_ITEM='Item';
 159      const IT_SEPARATOR='Separator';
 160      const IT_ALTERNATINGITEM='AlternatingItem';
 161      const IT_EDITITEM='EditItem';
 162      const IT_SELECTEDITEM='SelectedItem';
 163      const IT_PAGER='Pager';
 164  
 165      /**
 166       * Command name that TDataGrid understands.
 167       */
 168      const CMD_SELECT='Select';
 169      const CMD_EDIT='Edit';
 170      const CMD_UPDATE='Update';
 171      const CMD_DELETE='Delete';
 172      const CMD_CANCEL='Cancel';
 173      const CMD_SORT='Sort';
 174      const CMD_PAGE='Page';
 175      const CMD_PAGE_NEXT='Next';
 176      const CMD_PAGE_PREV='Previous';
 177  
 178      /**
 179       * @var TDataGridColumnCollection manually created column collection
 180       */
 181      private $_columns=null;
 182      /**
 183       * @var TDataGridColumnCollection automatically created column collection
 184       */
 185      private $_autoColumns=null;
 186      /**
 187       * @var TDataGridItemCollection datagrid item collection
 188       */
 189      private $_items=null;
 190      /**
 191       * @var TDataGridItem header item
 192       */
 193      private $_header=null;
 194      /**
 195       * @var TDataGridItem footer item
 196       */
 197      private $_footer=null;
 198      /**
 199       * @var TPagedDataSource paged data source object
 200       */
 201      private $_pagedDataSource=null;
 202      private $_topPager=null;
 203      private $_bottomPager=null;
 204      /**
 205       * @var ITemplate template used when empty data is bounded
 206       */
 207      private $_emptyTemplate=null;
 208      /**
 209       * @var boolean whether empty template is effective
 210       */
 211      private $_useEmptyTemplate=false;
 212  
 213      /**
 214       * @return string tag name (table) of the datagrid
 215       */
 216  	protected function getTagName()
 217      {
 218          return 'table';
 219      }
 220  
 221      /**
 222       * Adds objects parsed in template to datagrid.
 223       * Datagrid columns are added into {@link getColumns Columns} collection.
 224       * @param mixed object parsed in template
 225       */
 226  	public function addParsedObject($object)
 227      {
 228          if($object instanceof TDataGridColumn)
 229              $this->getColumns()->add($object);
 230          else
 231              parent::addParsedObject($object);  // this is needed by EmptyTemplate
 232      }
 233  
 234      /**
 235       * @return TDataGridColumnCollection manually specified datagrid columns
 236       */
 237  	public function getColumns()
 238      {
 239          if(!$this->_columns)
 240              $this->_columns=new TDataGridColumnCollection($this);
 241          return $this->_columns;
 242      }
 243  
 244      /**
 245       * @return TDataGridColumnCollection automatically generated datagrid columns
 246       */
 247  	public function getAutoColumns()
 248      {
 249          if(!$this->_autoColumns)
 250              $this->_autoColumns=new TDataGridColumnCollection($this);
 251          return $this->_autoColumns;
 252      }
 253  
 254      /**
 255       * @return TDataGridItemCollection datagrid item collection
 256       */
 257  	public function getItems()
 258      {
 259          if(!$this->_items)
 260              $this->_items=new TDataGridItemCollection;
 261          return $this->_items;
 262      }
 263  
 264      /**
 265       * @return integer number of items
 266       */
 267  	public function getItemCount()
 268      {
 269          return $this->_items?$this->_items->getCount():0;
 270      }
 271  
 272      /**
 273       * Creates a style object for the control.
 274       * This method creates a {@link TTableStyle} to be used by datagrid.
 275       * @return TTableStyle control style to be used
 276       */
 277  	protected function createStyle()
 278      {
 279          return new TTableStyle;
 280      }
 281  
 282      /**
 283       * @return string the URL of the background image for the datagrid
 284       */
 285  	public function getBackImageUrl()
 286      {
 287          return $this->getStyle()->getBackImageUrl();
 288      }
 289  
 290      /**
 291       * @param string the URL of the background image for the datagrid
 292       */
 293  	public function setBackImageUrl($value)
 294      {
 295          $this->getStyle()->setBackImageUrl($value);
 296      }
 297  
 298      /**
 299       * @return TTableItemStyle the style for every item
 300       */
 301  	public function getItemStyle()
 302      {
 303          if(($style=$this->getViewState('ItemStyle',null))===null)
 304          {
 305              $style=new TTableItemStyle;
 306              $this->setViewState('ItemStyle',$style,null);
 307          }
 308          return $style;
 309      }
 310  
 311      /**
 312       * @return TTableItemStyle the style for each alternating item
 313       */
 314  	public function getAlternatingItemStyle()
 315      {
 316          if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
 317          {
 318              $style=new TTableItemStyle;
 319              $this->setViewState('AlternatingItemStyle',$style,null);
 320          }
 321          return $style;
 322      }
 323  
 324      /**
 325       * @return TTableItemStyle the style for selected item
 326       */
 327  	public function getSelectedItemStyle()
 328      {
 329          if(($style=$this->getViewState('SelectedItemStyle',null))===null)
 330          {
 331              $style=new TTableItemStyle;
 332              $this->setViewState('SelectedItemStyle',$style,null);
 333          }
 334          return $style;
 335      }
 336  
 337      /**
 338       * @return TTableItemStyle the style for edit item
 339       */
 340  	public function getEditItemStyle()
 341      {
 342          if(($style=$this->getViewState('EditItemStyle',null))===null)
 343          {
 344              $style=new TTableItemStyle;
 345              $this->setViewState('EditItemStyle',$style,null);
 346          }
 347          return $style;
 348      }
 349  
 350      /**
 351       * @return TTableItemStyle the style for header
 352       */
 353  	public function getHeaderStyle()
 354      {
 355          if(($style=$this->getViewState('HeaderStyle',null))===null)
 356          {
 357              $style=new TTableItemStyle;
 358              $this->setViewState('HeaderStyle',$style,null);
 359          }
 360          return $style;
 361      }
 362  
 363      /**
 364       * @return TTableItemStyle the style for footer
 365       */
 366  	public function getFooterStyle()
 367      {
 368          if(($style=$this->getViewState('FooterStyle',null))===null)
 369          {
 370              $style=new TTableItemStyle;
 371              $this->setViewState('FooterStyle',$style,null);
 372          }
 373          return $style;
 374      }
 375  
 376      /**
 377       * @return TDataGridPagerStyle the style for pager
 378       */
 379  	public function getPagerStyle()
 380      {
 381          if(($style=$this->getViewState('PagerStyle',null))===null)
 382          {
 383              $style=new TDataGridPagerStyle;
 384              $this->setViewState('PagerStyle',$style,null);
 385          }
 386          return $style;
 387      }
 388  
 389      /**
 390       * @return string caption for the datagrid
 391       */
 392  	public function getCaption()
 393      {
 394          return $this->getViewState('Caption','');
 395      }
 396  
 397      /**
 398       * @param string caption for the datagrid
 399       */
 400  	public function setCaption($value)
 401      {
 402          $this->setViewState('Caption',$value,'');
 403      }
 404  
 405      /**
 406       * @return TTableCaptionAlign datagrid caption alignment. Defaults to TTableCaptionAlign::NotSet.
 407       */
 408  	public function getCaptionAlign()
 409      {
 410          return $this->getViewState('CaptionAlign',TTableCaptionAlign::NotSet);
 411      }
 412  
 413      /**
 414       * @param TTableCaptionAlign datagrid caption alignment. Valid values include
 415       */
 416  	public function setCaptionAlign($value)
 417      {
 418          $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'TTableCaptionAlign'),TTableCaptionAlign::NotSet);
 419      }
 420  
 421      /**
 422       * @return TDataGridItem the header item
 423       */
 424  	public function getHeader()
 425      {
 426          return $this->_header;
 427      }
 428  
 429      /**
 430       * @return TDataGridItem the footer item
 431       */
 432  	public function getFooter()
 433      {
 434          return $this->_footer;
 435      }
 436  
 437      /**
 438       * @return TDataGridPager the pager displayed at the top of datagrid. It could be null if paging is disabled.
 439       */
 440  	public function getTopPager()
 441      {
 442          return $this->_topPager;
 443      }
 444  
 445      /**
 446       * @return TDataGridPager the pager displayed at the bottom of datagrid. It could be null if paging is disabled.
 447       */
 448  	public function getBottomPager()
 449      {
 450          return $this->_bottomPager;
 451      }
 452  
 453      /**
 454       * @return TDataGridItem the selected item, null if no item is selected.
 455       */
 456  	public function getSelectedItem()
 457      {
 458          $index=$this->getSelectedItemIndex();
 459          $items=$this->getItems();
 460          if($index>=0 && $index<$items->getCount())
 461              return $items->itemAt($index);
 462          else
 463              return null;
 464      }
 465  
 466      /**
 467       * @return integer the zero-based index of the selected item in {@link getItems Items}.
 468       * A value -1 means no item selected.
 469       */
 470  	public function getSelectedItemIndex()
 471      {
 472          return $this->getViewState('SelectedItemIndex',-1);
 473      }
 474  
 475      /**
 476       * Selects an item by its index in {@link getItems Items}.
 477       * Previously selected item will be un-selected.
 478       * If the item to be selected is already in edit mode, it will remain in edit mode.
 479       * If the index is less than 0, any existing selection will be cleared up.
 480       * @param integer the selected item index
 481       */
 482  	public function setSelectedItemIndex($value)
 483      {
 484          if(($value=TPropertyValue::ensureInteger($value))<0)
 485              $value=-1;
 486          if(($current=$this->getSelectedItemIndex())!==$value)
 487          {
 488              $this->setViewState('SelectedItemIndex',$value,-1);
 489              $items=$this->getItems();
 490              $itemCount=$items->getCount();
 491              if($current>=0 && $current<$itemCount)
 492              {
 493                  $item=$items->itemAt($current);
 494                  if($item->getItemType()!==TListItemType::EditItem)
 495                      $item->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
 496              }
 497              if($value>=0 && $value<$itemCount)
 498              {
 499                  $item=$items->itemAt($value);
 500                  if($item->getItemType()!==TListItemType::EditItem)
 501                      $item->setItemType(TListItemType::SelectedItem);
 502              }
 503          }
 504      }
 505  
 506      /**
 507       * @return TDataGridItem the edit item
 508       */
 509  	public function getEditItem()
 510      {
 511          $index=$this->getEditItemIndex();
 512          $items=$this->getItems();
 513          if($index>=0 && $index<$items->getCount())
 514              return $items->itemAt($index);
 515          else
 516              return null;
 517      }
 518  
 519      /**
 520       * @return integer the zero-based index of the edit item in {@link getItems Items}.
 521       * A value -1 means no item is in edit mode.
 522       */
 523  	public function getEditItemIndex()
 524      {
 525          return $this->getViewState('EditItemIndex',-1);
 526      }
 527  
 528      /**
 529       * Edits an item by its index in {@link getItems Items}.
 530       * Previously editting item will change to normal item state.
 531       * If the index is less than 0, any existing edit item will be cleared up.
 532       * @param integer the edit item index
 533       */
 534  	public function setEditItemIndex($value)
 535      {
 536          if(($value=TPropertyValue::ensureInteger($value))<0)
 537              $value=-1;
 538          if(($current=$this->getEditItemIndex())!==$value)
 539          {
 540              $this->setViewState('EditItemIndex',$value,-1);
 541              $items=$this->getItems();
 542              $itemCount=$items->getCount();
 543              if($current>=0 && $current<$itemCount)
 544                  $items->itemAt($current)->setItemType($current%2?TListItemType::AlternatingItem:TListItemType::Item);
 545              if($value>=0 && $value<$itemCount)
 546                  $items->itemAt($value)->setItemType(TListItemType::EditItem);
 547          }
 548      }
 549  
 550      /**
 551       * @return boolean whether sorting is enabled. Defaults to false.
 552       */
 553  	public function getAllowSorting()
 554      {
 555          return $this->getViewState('AllowSorting',false);
 556      }
 557  
 558      /**
 559       * @param boolean whether sorting is enabled
 560       */
 561  	public function setAllowSorting($value)
 562      {
 563          $this->setViewState('AllowSorting',TPropertyValue::ensureBoolean($value),false);
 564      }
 565  
 566      /**
 567       * @return boolean whether datagrid columns should be automatically generated. Defaults to true.
 568       */
 569  	public function getAutoGenerateColumns()
 570      {
 571          return $this->getViewState('AutoGenerateColumns',true);
 572      }
 573  
 574      /**
 575       * @param boolean whether datagrid columns should be automatically generated
 576       */
 577  	public function setAutoGenerateColumns($value)
 578      {
 579          $this->setViewState('AutoGenerateColumns',TPropertyValue::ensureBoolean($value),true);
 580      }
 581  
 582      /**
 583       * @return boolean whether the header should be displayed. Defaults to true.
 584       */
 585  	public function getShowHeader()
 586      {
 587          return $this->getViewState('ShowHeader',true);
 588      }
 589  
 590      /**
 591       * @param boolean whether the header should be displayed
 592       */
 593  	public function setShowHeader($value)
 594      {
 595          $this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
 596      }
 597  
 598      /**
 599       * @return boolean whether the footer should be displayed. Defaults to false.
 600       */
 601  	public function getShowFooter()
 602      {
 603          return $this->getViewState('ShowFooter',false);
 604      }
 605  
 606      /**
 607       * @param boolean whether the footer should be displayed
 608       */
 609  	public function setShowFooter($value)
 610      {
 611          $this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),false);
 612      }
 613  
 614      /**
 615       * @return ITemplate the template applied when no data is bound to the datagrid
 616       */
 617  	public function getEmptyTemplate()
 618      {
 619          return $this->_emptyTemplate;
 620      }
 621  
 622      /**
 623       * @param ITemplate the template applied when no data is bound to the datagrid
 624       * @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
 625       */
 626  	public function setEmptyTemplate($value)
 627      {
 628          if($value instanceof ITemplate || $value===null)
 629              $this->_emptyTemplate=$value;
 630          else
 631              throw new TInvalidDataTypeException('datagrid_template_required','EmptyTemplate');
 632      }
 633  
 634      /**
 635       * This method overrides parent's implementation to handle
 636       * {@link onItemCommand OnItemCommand} event which is bubbled from
 637       * {@link TDataGridItem} child controls.
 638       * If the event parameter is {@link TDataGridCommandEventParameter} and
 639       * the command name is a recognized one, which includes 'select', 'edit',
 640       * 'delete', 'update', and 'cancel' (case-insensitive), then a
 641       * corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
 642       * This method should only be used by control developers.
 643       * @param TControl the sender of the event
 644       * @param TEventParameter event parameter
 645       * @return boolean whether the event bubbling should stop here.
 646       */
 647  	public function bubbleEvent($sender,$param)
 648      {
 649          if($param instanceof TDataGridCommandEventParameter)
 650          {
 651              $this->onItemCommand($param);
 652              $command=$param->getCommandName();
 653              if(strcasecmp($command,self::CMD_SELECT)===0)
 654              {
 655                  $this->setSelectedItemIndex($param->getItem()->getItemIndex());
 656                  $this->onSelectedIndexChanged($param);
 657                  return true;
 658              }
 659              else if(strcasecmp($command,self::CMD_EDIT)===0)
 660              {
 661                  $this->onEditCommand($param);
 662                  return true;
 663              }
 664              else if(strcasecmp($command,self::CMD_DELETE)===0)
 665              {
 666                  $this->onDeleteCommand($param);
 667                  return true;
 668              }
 669              else if(strcasecmp($command,self::CMD_UPDATE)===0)
 670              {
 671                  $this->onUpdateCommand($param);
 672                  return true;
 673              }
 674              else if(strcasecmp($command,self::CMD_CANCEL)===0)
 675              {
 676                  $this->onCancelCommand($param);
 677                  return true;
 678              }
 679              else if(strcasecmp($command,self::CMD_SORT)===0)
 680              {
 681                  $this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param));
 682                  return true;
 683              }
 684              else if(strcasecmp($command,self::CMD_PAGE)===0)
 685              {
 686                  $p=$param->getCommandParameter();
 687                  if(strcasecmp($p,self::CMD_PAGE_NEXT)===0)
 688                      $pageIndex=$this->getCurrentPageIndex()+1;
 689                  else if(strcasecmp($p,self::CMD_PAGE_PREV)===0)
 690                      $pageIndex=$this->getCurrentPageIndex()-1;
 691                  else
 692                      $pageIndex=TPropertyValue::ensureInteger($p)-1;
 693                  $this->onPageIndexChanged(new TDataGridPageChangedEventParameter($sender,$pageIndex));
 694                  return true;
 695              }
 696          }
 697          return false;
 698      }
 699  
 700      /**
 701       * Raises <b>OnCancelCommand</b> event.
 702       * This method is invoked when a button control raises <b>OnCommand</b> event
 703       * with <b>cancel</b> command name.
 704       * @param TDataGridCommandEventParameter event parameter
 705       */
 706  	public function onCancelCommand($param)
 707      {
 708          $this->raiseEvent('OnCancelCommand',$this,$param);
 709      }
 710  
 711      /**
 712       * Raises <b>OnDeleteCommand</b> event.
 713       * This method is invoked when a button control raises <b>OnCommand</b> event
 714       * with <b>delete</b> command name.
 715       * @param TDataGridCommandEventParameter event parameter
 716       */
 717  	public function onDeleteCommand($param)
 718      {
 719          $this->raiseEvent('OnDeleteCommand',$this,$param);
 720      }
 721  
 722      /**
 723       * Raises <b>OnEditCommand</b> event.
 724       * This method is invoked when a button control raises <b>OnCommand</b> event
 725       * with <b>edit</b> command name.
 726       * @param TDataGridCommandEventParameter event parameter
 727       */
 728  	public function onEditCommand($param)
 729      {
 730          $this->raiseEvent('OnEditCommand',$this,$param);
 731      }
 732  
 733      /**
 734       * Raises <b>OnItemCommand</b> event.
 735       * This method is invoked when a button control raises <b>OnCommand</b> event.
 736       * @param TDataGridCommandEventParameter event parameter
 737       */
 738  	public function onItemCommand($param)
 739      {
 740          $this->raiseEvent('OnItemCommand',$this,$param);
 741      }
 742  
 743      /**
 744       * Raises <b>OnSortCommand</b> event.
 745       * This method is invoked when a button control raises <b>OnCommand</b> event
 746       * with <b>sort</b> command name.
 747       * @param TDataGridSortCommandEventParameter event parameter
 748       */
 749  	public function onSortCommand($param)
 750      {
 751          $this->raiseEvent('OnSortCommand',$this,$param);
 752      }
 753  
 754      /**
 755       * Raises <b>OnUpdateCommand</b> event.
 756       * This method is invoked when a button control raises <b>OnCommand</b> event
 757       * with <b>update</b> command name.
 758       * @param TDataGridCommandEventParameter event parameter
 759       */
 760  	public function onUpdateCommand($param)
 761      {
 762          $this->raiseEvent('OnUpdateCommand',$this,$param);
 763      }
 764  
 765      /**
 766       * Raises <b>OnItemCreated</b> event.
 767       * This method is invoked right after a datagrid item is created and before
 768       * added to page hierarchy.
 769       * @param TDataGridItemEventParameter event parameter
 770       */
 771  	public function onItemCreated($param)
 772      {
 773          $this->raiseEvent('OnItemCreated',$this,$param);
 774      }
 775  
 776      /**
 777       * Raises <b>OnPagerCreated</b> event.
 778       * This method is invoked right after a datagrid pager is created and before
 779       * added to page hierarchy.
 780       * @param TDataGridPagerEventParameter event parameter
 781       */
 782  	public function onPagerCreated($param)
 783      {
 784          $this->raiseEvent('OnPagerCreated',$this,$param);
 785      }
 786  
 787      /**
 788       * Raises <b>OnItemDataBound</b> event.
 789       * This method is invoked for each datagrid item after it performs
 790       * databinding.
 791       * @param TDataGridItemEventParameter event parameter
 792       */
 793  	public function onItemDataBound($param)
 794      {
 795          $this->raiseEvent('OnItemDataBound',$this,$param);
 796      }
 797  
 798      /**
 799       * Raises <b>OnPageIndexChanged</b> event.
 800       * This method is invoked when current page is changed.
 801       * @param TDataGridPageChangedEventParameter event parameter
 802       */
 803  	public function onPageIndexChanged($param)
 804      {
 805          $this->raiseEvent('OnPageIndexChanged',$this,$param);
 806      }
 807  
 808      /**
 809       * Saves item count in viewstate.
 810       * This method is invoked right before control state is to be saved.
 811       */
 812  	public function saveState()
 813      {
 814          parent::saveState();
 815          if(!$this->getEnableViewState(true))
 816              return;
 817          if($this->_items)
 818              $this->setViewState('ItemCount',$this->_items->getCount(),0);
 819          else
 820              $this->clearViewState('ItemCount');
 821          if($this->_autoColumns)
 822          {
 823              $state=array();
 824              foreach($this->_autoColumns as $column)
 825                  $state[]=$column->saveState();
 826              $this->setViewState('AutoColumns',$state,array());
 827          }
 828          else
 829              $this->clearViewState('AutoColumns');
 830          if($this->_columns)
 831          {
 832              $state=array();
 833              foreach($this->_columns as $column)
 834                  $state[]=$column->saveState();
 835              $this->setViewState('Columns',$state,array());
 836          }
 837          else
 838              $this->clearViewState('Columns');
 839      }
 840  
 841      /**
 842       * Loads item count information from viewstate.
 843       * This method is invoked right after control state is loaded.
 844       */
 845  	public function loadState()
 846      {
 847          parent::loadState();
 848          if(!$this->getEnableViewState(true))
 849              return;
 850          if(!$this->getIsDataBound())
 851          {
 852              $state=$this->getViewState('AutoColumns',array());
 853              if(!empty($state))
 854              {
 855                  $this->_autoColumns=new TDataGridColumnCollection($this);
 856                  foreach($state as $st)
 857                  {
 858                      $column=new TBoundColumn;
 859                      $column->loadState($st);
 860                      $this->_autoColumns->add($column);
 861                  }
 862              }
 863              else
 864                  $this->_autoColumns=null;
 865              $state=$this->getViewState('Columns',array());
 866              if($this->_columns && $this->_columns->getCount()===count($state))
 867              {
 868                  $i=0;
 869                  foreach($this->_columns as $column)
 870                  {
 871                      $column->loadState($state[$i]);
 872                      $i++;
 873                  }
 874              }
 875              $this->restoreGridFromViewState();
 876          }
 877      }
 878  
 879      /**
 880       * Clears up all items in the datagrid.
 881       */
 882  	public function reset()
 883      {
 884          $this->getControls()->clear();
 885          $this->getItems()->clear();
 886          $this->_header=null;
 887          $this->_footer=null;
 888          $this->_topPager=null;
 889          $this->_bottomPager=null;
 890          $this->_useEmptyTemplate=false;
 891      }
 892  
 893      /**
 894       * Restores datagrid content from viewstate.
 895       */
 896  	protected function restoreGridFromViewState()
 897      {
 898          $this->reset();
 899  
 900          $allowPaging=$this->getAllowPaging();
 901  
 902          $itemCount=$this->getViewState('ItemCount',0);
 903          $dsIndex=$this->getViewState('DataSourceIndex',0);
 904  
 905          $columns=new TList($this->getColumns());
 906          $columns->mergeWith($this->_autoColumns);
 907  
 908          $items=$this->getItems();
 909  
 910          if($columns->getCount())
 911          {
 912              foreach($columns as $column)
 913                  $column->initialize();
 914              $selectedIndex=$this->getSelectedItemIndex();
 915              $editIndex=$this->getEditItemIndex();
 916              for($index=0;$index<$itemCount;++$index)
 917              {
 918                  if($index===0)
 919                  {
 920                      if($allowPaging)
 921                          $this->_topPager=$this->createPager();
 922                      $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,false,null,$columns);
 923                  }
 924                  if($index===$editIndex)
 925                      $itemType=TListItemType::EditItem;
 926                  else if($index===$selectedIndex)
 927                      $itemType=TListItemType::SelectedItem;
 928                  else if($index % 2)
 929                      $itemType=TListItemType::AlternatingItem;
 930                  else
 931                      $itemType=TListItemType::Item;
 932                  $items->add($this->createItemInternal($index,$dsIndex,$itemType,false,null,$columns));
 933                  $dsIndex++;
 934              }
 935              if($index>0)
 936              {
 937                  $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,false,null,$columns);
 938                  if($allowPaging)
 939                      $this->_bottomPager=$this->createPager();
 940              }
 941          }
 942          if(!$dsIndex && $this->_emptyTemplate!==null)
 943          {
 944              $this->_useEmptyTemplate=true;
 945              $this->_emptyTemplate->instantiateIn($this);
 946          }
 947      }
 948  
 949      /**
 950       * Performs databinding to populate datagrid items from data source.
 951       * This method is invoked by {@link dataBind()}.
 952       * You may override this function to provide your own way of data population.
 953       * @param Traversable the bound data
 954       */
 955  	protected function performDataBinding($data)
 956      {
 957          $this->reset();
 958          $keys=$this->getDataKeys();
 959          $keys->clear();
 960          $keyField=$this->getDataKeyField();
 961  
 962          // get all columns
 963          if($this->getAutoGenerateColumns())
 964          {
 965              $columns=new TList($this->getColumns());
 966              $autoColumns=$this->createAutoColumns($data);
 967              $columns->mergeWith($autoColumns);
 968          }
 969          else
 970              $columns=$this->getColumns();
 971  
 972          $items=$this->getItems();
 973  
 974          $index=0;
 975          $allowPaging=$this->getAllowPaging() && ($data instanceof TPagedDataSource);
 976          $dsIndex=$allowPaging?$data->getFirstIndexInPage():0;
 977          $this->setViewState('DataSourceIndex',$dsIndex,0);
 978          if($columns->getCount())
 979          {
 980              foreach($columns as $column)
 981                  $column->initialize();
 982  
 983              $selectedIndex=$this->getSelectedItemIndex();
 984              $editIndex=$this->getEditItemIndex();
 985              foreach($data as $key=>$row)
 986              {
 987                  if($keyField!=='')
 988                      $keys->add($this->getDataFieldValue($row,$keyField));
 989                  else
 990                      $keys->add($key);
 991                  if($index===0)
 992                  {
 993                      if($allowPaging)
 994                          $this->_topPager=$this->createPager();
 995                      $this->_header=$this->createItemInternal(-1,-1,TListItemType::Header,true,null,$columns);
 996                  }
 997                  if($index===$editIndex)
 998                      $itemType=TListItemType::EditItem;
 999                  else if($index===$selectedIndex)
1000                      $itemType=TListItemType::SelectedItem;
1001                  else if($index % 2)
1002                      $itemType=TListItemType::AlternatingItem;
1003                  else
1004                      $itemType=TListItemType::Item;
1005                  $items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$row,$columns));
1006                  $index++;
1007                  $dsIndex++;
1008              }
1009              if($index>0)
1010              {
1011                  $this->_footer=$this->createItemInternal(-1,-1,TListItemType::Footer,true,null,$columns);
1012                  if($allowPaging)
1013                      $this->_bottomPager=$this->createPager();
1014              }
1015          }
1016          $this->setViewState('ItemCount',$index,0);
1017          if(!$dsIndex && $this->_emptyTemplate!==null)
1018          {
1019              $this->_useEmptyTemplate=true;
1020              $this->_emptyTemplate->instantiateIn($this);
1021              $this->dataBindChildren();
1022          }
1023      }
1024  
1025      /**
1026       * Creates a datagrid item instance based on the item type and index.
1027       * @param integer zero-based item index
1028       * @param TListItemType item type
1029       * @return TDataGridItem created data list item
1030       */
1031  	protected function createItem($itemIndex,$dataSourceIndex,$itemType)
1032      {
1033          return new TDataGridItem($itemIndex,$dataSourceIndex,$itemType);
1034      }
1035  
1036  	private function createItemInternal($itemIndex,$dataSourceIndex,$itemType,$dataBind,$dataItem,$columns)
1037      {
1038          $item=$this->createItem($itemIndex,$dataSourceIndex,$itemType);
1039          $this->initializeItem($item,$columns);
1040          $param=new TDataGridItemEventParameter($item);
1041          if($dataBind)
1042          {
1043              $item->setDataItem($dataItem);
1044              $this->onItemCreated($param);
1045              $this->getControls()->add($item);
1046              $item->dataBind();
1047              $this->onItemDataBound($param);
1048              $item->setDataItem(null);
1049          }
1050          else
1051          {
1052              $this->onItemCreated($param);
1053              $this->getControls()->add($item);
1054          }
1055          return $item;
1056      }
1057  
1058      /**
1059       * Initializes a datagrid item and cells inside it
1060       * @param TDataGrid datagrid item to be initialized
1061       * @param TDataGridColumnCollection datagrid columns to be used to initialize the cells in the item
1062       */
1063  	protected function initializeItem($item,$columns)
1064      {
1065          $cells=$item->getCells();
1066          $itemType=$item->getItemType();
1067          $index=0;
1068          foreach($columns as $column)
1069          {
1070              if($itemType===TListItemType::Header)
1071                  $cell=new TTableHeaderCell;
1072              else
1073                  $cell=new TTableCell;
1074              if(($id=$column->getID())!=='')
1075                  $item->registerObject($id,$cell);
1076              $column->initializeCell($cell,$index,$itemType);
1077              $cells->add($cell);
1078              $index++;
1079          }
1080      }
1081  
1082  	private function createPager()
1083      {
1084          $pager=new TDataGridPager($this);
1085          $this->buildPager($pager);
1086          $this->onPagerCreated(new TDataGridPagerEventParameter($pager));
1087          $this->getControls()->add($pager);
1088          return $pager;
1089      }
1090  
1091      /**
1092       * Builds the pager content based on pager style.
1093       * @param TDataGridPager the container for the pager
1094       */
1095  	protected function buildPager($pager)
1096      {
1097          switch($this->getPagerStyle()->getMode())
1098          {
1099              case TDataGridPagerMode::NextPrev:
1100                  $this->buildNextPrevPager($pager);
1101                  break;
1102              case TDataGridPagerMode::Numeric:
1103                  $this->buildNumericPager($pager);
1104                  break;
1105          }
1106      }
1107  
1108      /**
1109       * Creates a pager button.
1110       * Depending on the button type, a TLinkButton or a TButton may be created.
1111       * If it is enabled (clickable), its command name and parameter will also be set.
1112       * Derived classes may override this method to create additional types of buttons, such as TImageButton.
1113       * @param string button type, either LinkButton or PushButton
1114       * @param boolean whether the button should be enabled
1115       * @param string caption of the button
1116       * @param string CommandName corresponding to the OnCommand event of the button
1117       * @param string CommandParameter corresponding to the OnCommand event of the button
1118       * @return mixed the button instance
1119       */
1120  	protected function createPagerButton($buttonType,$enabled,$text,$commandName,$commandParameter)
1121      {
1122          if($buttonType===TDataGridPagerButtonType::LinkButton)
1123          {
1124              if($enabled)
1125                  $button=new TLinkButton;
1126              else
1127              {
1128                  $button=new TLabel;
1129                  $button->setText($text);
1130                  return $button;
1131              }
1132          }
1133          else
1134          {
1135              $button=new TButton;
1136              if(!$enabled)
1137                  $button->setEnabled(false);
1138          }
1139          $button->setText($text);
1140          $button->setCommandName($commandName);
1141          $button->setCommandParameter($commandParameter);
1142          $button->setCausesValidation(false);
1143          return $button;
1144      }
1145  
1146      /**
1147       * Builds a next-prev pager
1148       * @param TDataGridPager the container for the pager
1149       */
1150  	protected function buildNextPrevPager($pager)
1151      {
1152          $style=$this->getPagerStyle();
1153          $buttonType=$style->getButtonType();
1154          $controls=$pager->getControls();
1155          $currentPageIndex=$this->getCurrentPageIndex();
1156          if($currentPageIndex===0)
1157          {
1158              $label=$this->createPagerButton($buttonType,false,$style->getPrevPageText(),'','');
1159              $controls->add($label);
1160          }
1161          else
1162          {
1163              $button=$this->createPagerButton($buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,self::CMD_PAGE_PREV);
1164              $controls->add($button);
1165          }
1166          $controls->add("\n");
1167          if($currentPageIndex===$this->getPageCount()-1)
1168          {
1169              $label=$this->createPagerButton($buttonType,false,$style->getNextPageText(),'','');
1170              $controls->add($label);
1171          }
1172          else
1173          {
1174              $button=$this->createPagerButton($buttonType,true,$style->getNextPageText(),self::CMD_PAGE,self::CMD_PAGE_NEXT);
1175              $controls->add($button);
1176          }
1177      }
1178  
1179      /**
1180       * Builds a numeric pager
1181       * @param TDataGridPager the container for the pager
1182       */
1183  	protected function buildNumericPager($pager)
1184      {
1185          $style=$this->getPagerStyle();
1186          $buttonType=$style->getButtonType();
1187          $controls=$pager->getControls();
1188          $pageCount=$this->getPageCount();
1189          $pageIndex=$this->getCurrentPageIndex()+1;
1190          $maxButtonCount=$style->getPageButtonCount();
1191          $buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
1192          $startPageIndex=1;
1193          $endPageIndex=$buttonCount;
1194          if($pageIndex>$endPageIndex)
1195          {
1196              $startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
1197              if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
1198                  $endPageIndex=$pageCount;
1199              if($endPageIndex-$startPageIndex+1<$maxButtonCount)
1200              {
1201                  if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
1202                      $startPageIndex=1;
1203              }
1204          }
1205  
1206          if($startPageIndex>1)
1207          {
1208              $prevPageIndex=$startPageIndex-1;
1209              $button=$this->createPagerButton($buttonType,true,$style->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
1210              $controls->add($button);
1211              $controls->add("\n");
1212          }
1213  
1214          for($i=$startPageIndex;$i<=$endPageIndex;++$i)
1215          {
1216              if($i===$pageIndex)
1217              {
1218                  $label=$this->createPagerButton($buttonType,false,"$i",'','');
1219                  $controls->add($label);
1220              }
1221              else
1222              {
1223                  $button=$this->createPagerButton($buttonType,true,"$i",self::CMD_PAGE,"$i");
1224                  $controls->add($button);
1225              }
1226              if($i<$endPageIndex)
1227                  $controls->add("\n");
1228          }
1229  
1230          if($pageCount>$endPageIndex)
1231          {
1232              $controls->add("\n");
1233              $nextPageIndex=$endPageIndex+1;
1234              $button=$this->createPagerButton($buttonType,true,$style->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
1235              $controls->add($button);
1236          }
1237      }
1238  
1239      /**
1240       * Automatically generates datagrid columns based on datasource schema
1241       * @param Traversable data source bound to the datagrid
1242       * @return TDataGridColumnCollection
1243       */
1244  	protected function createAutoColumns($dataSource)
1245      {
1246          if(!$dataSource)
1247              return null;
1248          $autoColumns=$this->getAutoColumns();
1249          $autoColumns->clear();
1250          foreach($dataSource as $row)
1251          {
1252              foreach($row as $key=>$value)
1253              {
1254                  $column=new TBoundColumn;
1255                  if(is_string($key))
1256                  {
1257                      $column->setHeaderText($key);
1258                      $column->setDataField($key);
1259                      $column->setSortExpression($key);
1260                      $autoColumns->add($column);
1261                  }
1262                  else
1263                  {
1264                      $column->setHeaderText(TListItemType::Item);
1265                      $column->setDataField($key);
1266                      $column->setSortExpression(TListItemType::Item);
1267                      $autoColumns->add($column);
1268                  }
1269              }
1270              break;
1271          }
1272          return $autoColumns;
1273      }
1274  
1275      /**
1276       * Applies styles to items, header, footer and separators.
1277       * Item styles are applied in a hierarchical way. Style in higher hierarchy
1278       * will inherit from styles in lower hierarchy.
1279       * Starting from the lowest hierarchy, the item styles include
1280       * item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
1281       * {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
1282       * Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
1283       * {@link getEditItemStyle EditItemStyle} will also have red background color
1284       * unless it is set to a different value explicitly.
1285       */
1286  	protected function applyItemStyles()
1287      {
1288          $itemStyle=$this->getViewState('ItemStyle',null);
1289  
1290          $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
1291          if($itemStyle!==null)
1292          {
1293              if($alternatingItemStyle===null)
1294                  $alternatingItemStyle=$itemStyle;
1295              else
1296                  $alternatingItemStyle->mergeWith($itemStyle);
1297          }
1298  
1299          $selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
1300  
1301          $editItemStyle=$this->getViewState('EditItemStyle',null);
1302          if($selectedItemStyle!==null)
1303          {
1304              if($editItemStyle===null)
1305                  $editItemStyle=$selectedItemStyle;
1306              else
1307                  $editItemStyle->mergeWith($selectedItemStyle);
1308          }
1309  
1310          $headerStyle=$this->getViewState('HeaderStyle',null);
1311          $footerStyle=$this->getViewState('FooterStyle',null);
1312          $pagerStyle=$this->getViewState('PagerStyle',null);
1313          $separatorStyle=$this->getViewState('SeparatorStyle',null);
1314  
1315          foreach($this->getControls() as $index=>$item)
1316          {
1317              if(!($item instanceof TDataGridItem) && !($item instanceof TDataGridPager))
1318                  continue;
1319              $itemType=$item->getItemType();
1320              switch($itemType)
1321              {
1322                  case TListItemType::Header:
1323                      if($headerStyle)
1324                          $item->getStyle()->mergeWith($headerStyle);
1325                      if(!$this->getShowHeader())
1326                          $item->setVisible(false);
1327                      break;
1328                  case TListItemType::Footer:
1329                      if($footerStyle)
1330                          $item->getStyle()->mergeWith($footerStyle);
1331                      if(!$this->getShowFooter())
1332                          $item->setVisible(false);
1333                      break;
1334                  case TListItemType::Separator:
1335                      if($separatorStyle)
1336                          $item->getStyle()->mergeWith($separatorStyle);
1337                      break;
1338                  case TListItemType::Item:
1339                      if($itemStyle)
1340                          $item->getStyle()->mergeWith($itemStyle);
1341                      break;
1342                  case TListItemType::AlternatingItem:
1343                      if($alternatingItemStyle)
1344                          $item->getStyle()->mergeWith($alternatingItemStyle);
1345                      break;
1346                  case TListItemType::SelectedItem:
1347                      if($selectedItemStyle)
1348                          $item->getStyle()->mergeWith($selectedItemStyle);
1349                      if($index % 2==1)
1350                      {
1351                          if($itemStyle)
1352                              $item->getStyle()->mergeWith($itemStyle);
1353                      }
1354                      else
1355                      {
1356                          if($alternatingItemStyle)
1357                              $item->getStyle()->mergeWith($alternatingItemStyle);
1358                      }
1359                      break;
1360                  case TListItemType::EditItem:
1361                      if($editItemStyle)
1362                          $item->getStyle()->mergeWith($editItemStyle);
1363                      if($index % 2==1)
1364                      {
1365                          if($itemStyle)
1366                              $item->getStyle()->mergeWith($itemStyle);
1367                      }
1368                      else
1369                      {
1370                          if($alternatingItemStyle)
1371                              $item->getStyle()->mergeWith($alternatingItemStyle);
1372                      }
1373                      break;
1374                  case TListItemType::Pager:
1375                      if($pagerStyle)
1376                      {
1377                          $item->getStyle()->mergeWith($pagerStyle);
1378                          if($index===0)
1379                          {
1380                              if($pagerStyle->getPosition()===TDataGridPagerPosition::Bottom || !$pagerStyle->getVisible())
1381                                  $item->setVisible(false);
1382                          }
1383                          else
1384                          {
1385                              if($pagerStyle->getPosition()===TDataGridPagerPosition::Top || !$pagerStyle->getVisible())
1386                                  $item->setVisible(false);
1387                          }
1388                      }
1389                      break;
1390                  default:
1391                      break;
1392              }
1393              if($this->_columns && $itemType!==TListItemType::Pager)
1394              {
1395                  $n=$this->_columns->getCount();
1396                  $cells=$item->getCells();
1397                  for($i=0;$i<$n;++$i)
1398                  {
1399                      $cell=$cells->itemAt($i);
1400                      $column=$this->_columns->itemAt($i);
1401                      if(!$column->getVisible())
1402                          $cell->setVisible(false);
1403                      else
1404                      {
1405                          if($itemType===TListItemType::Header)
1406                              $style=$column->getHeaderStyle(false);
1407                          else if($itemType===TListItemType::Footer)
1408                              $style=$column->getFooterStyle(false);
1409                          else
1410                              $style=$column->getItemStyle(false);
1411                          if($style!==null)
1412                              $cell->getStyle()->mergeWith($style);
1413                      }
1414                  }
1415              }
1416          }
1417      }
1418  
1419      /**
1420       * Renders the openning tag for the datagrid control which will render table caption if present.
1421       * @param THtmlWriter the writer used for the rendering purpose
1422       */
1423  	public function renderBeginTag($writer)
1424      {
1425          parent::renderBeginTag($writer);
1426          if(($caption=$this->getCaption())!=='')
1427          {
1428              if(($align=$this->getCaptionAlign())!==TTableCaptionAlign::NotSet)
1429                  $writer->addAttribute('align',strtolower($align));
1430              $writer->renderBeginTag('caption');
1431              $writer->write($caption);
1432              $writer->renderEndTag();
1433          }
1434      }
1435  
1436      /**
1437       * Renders the datagrid.
1438       * @param THtmlWriter writer for the rendering purpose
1439       */
1440  	public function render($writer)
1441      {
1442          if($this->getHasControls())
1443          {
1444              if($this->_useEmptyTemplate)
1445              {
1446                  $control=new TWebControl;
1447                  $control->setID($this->getClientID());
1448                  $control->copyBaseAttributes($this);
1449                  if($this->getHasStyle())
1450                      $control->getStyle()->copyFrom($this->getStyle());
1451                  $control->renderBeginTag($writer);
1452                  $this->renderContents($writer);
1453                  $control->renderEndTag($writer);
1454              }
1455              else if($this->getViewState('ItemCount',0)>0)
1456              {
1457                  $this->applyItemStyles();
1458                  if($this->_topPager)
1459                  {
1460                      $this->_topPager->renderControl($writer);
1461                      $writer->writeLine();
1462                  }
1463                  $this->renderTable($writer);
1464                  if($this->_bottomPager)
1465                  {
1466                      $writer->writeLine();
1467                      $this->_bottomPager->renderControl($writer);
1468                  }
1469              }
1470          }
1471      }
1472  
1473      /**
1474       * Renders the tabular data.
1475       * @param THtmlWriter writer
1476       */
1477  	protected function renderTable($writer)
1478      {
1479          $this->renderBeginTag($writer);
1480          if($this->_header && $this->_header->getVisible())
1481          {
1482              $writer->writeLine();
1483              $writer->renderBeginTag('thead');
1484              $this->_header->render($writer);
1485              $writer->renderEndTag();
1486          }
1487          $writer->writeLine();
1488          $writer->renderBeginTag('tbody');
1489          foreach($this->getItems() as $item)
1490              $item->renderControl($writer);
1491          $writer->renderEndTag();
1492  
1493          if($this->_footer && $this->_footer->getVisible())
1494          {
1495              $writer->writeLine();
1496              $writer->renderBeginTag('tfoot');
1497              $this->_footer->render($writer);
1498              $writer->renderEndTag();
1499          }
1500  
1501          $writer->writeLine();
1502          $this->renderEndTag($writer);
1503      }
1504  }
1505  
1506  /**
1507   * TDataGridItemEventParameter class
1508   *
1509   * TDataGridItemEventParameter encapsulates the parameter data for
1510   * {@link TDataGrid::onItemCreated OnItemCreated} event of {@link TDataGrid} controls.
1511   * The {@link getItem Item} property indicates the datagrid item related with the event.
1512   *
1513   * @author Qiang Xue <qiang.xue@gmail.com>
1514   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1515   * @package System.Web.UI.WebControls
1516   * @since 3.0
1517   */
1518  class TDataGridItemEventParameter extends TEventParameter
1519  {
1520      /**
1521       * The TDataGridItem control responsible for the event.
1522       * @var TDataGridItem
1523       */
1524      private $_item=null;
1525  
1526      /**
1527       * Constructor.
1528       * @param TDataGridItem datagrid item related with the corresponding event
1529       */
1530  	public function __construct(TDataGridItem $item)
1531      {
1532          $this->_item=$item;
1533      }
1534  
1535      /**
1536       * @return TDataGridItem datagrid item related with the corresponding event
1537       */
1538  	public function getItem()
1539      {
1540          return $this->_item;
1541      }
1542  }
1543  
1544  /**
1545   * TDataGridPagerEventParameter class
1546   *
1547   * TDataGridPagerEventParameter encapsulates the parameter data for
1548   * {@link TDataGrid::onPagerCreated OnPagerCreated} event of {@link TDataGrid} controls.
1549   * The {@link getPager Pager} property indicates the datagrid pager related with the event.
1550   *
1551   * @author Qiang Xue <qiang.xue@gmail.com>
1552   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1553   * @package System.Web.UI.WebControls
1554   * @since 3.0
1555   */
1556  class TDataGridPagerEventParameter extends TEventParameter
1557  {
1558      /**
1559       * The TDataGridPager control responsible for the event.
1560       * @var TDataGridPager
1561       */
1562      private $_pager=null;
1563  
1564      /**
1565       * Constructor.
1566       * @param TDataGridPager datagrid pager related with the corresponding event
1567       */
1568  	public function __construct(TDataGridPager $pager)
1569      {
1570          $this->_pager=$pager;
1571      }
1572  
1573      /**
1574       * @return TDataGridPager datagrid pager related with the corresponding event
1575       */
1576  	public function getPager()
1577      {
1578          return $this->_pager;
1579      }
1580  }
1581  
1582  /**
1583   * TDataGridCommandEventParameter class
1584   *
1585   * TDataGridCommandEventParameter encapsulates the parameter data for
1586   * {@link TDataGrid::onItemCommand ItemCommand} event of {@link TDataGrid} controls.
1587   *
1588   * The {@link getItem Item} property indicates the datagrid item related with the event.
1589   * The {@link getCommandSource CommandSource} refers to the control that originally
1590   * raises the Command event.
1591   *
1592   * @author Qiang Xue <qiang.xue@gmail.com>
1593   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1594   * @package System.Web.UI.WebControls
1595   * @since 3.0
1596   */
1597  class TDataGridCommandEventParameter extends TCommandEventParameter
1598  {
1599      /**
1600       * @var TDataGridItem the TDataGridItem control responsible for the event.
1601       */
1602      private $_item=null;
1603      /**
1604       * @var TControl the control originally raises the <b>Command</b> event.
1605       */
1606      private $_source=null;
1607  
1608      /**
1609       * Constructor.
1610       * @param TDataGridItem datagrid item responsible for the event
1611       * @param TControl original event sender
1612       * @param TCommandEventParameter original event parameter
1613       */
1614  	public function __construct($item,$source,TCommandEventParameter $param)
1615      {
1616          $this->_item=$item;
1617          $this->_source=$source;
1618          parent::__construct($param->getCommandName(),$param->getCommandParameter());
1619      }
1620  
1621      /**
1622       * @return TDataGridItem the TDataGridItem control responsible for the event.
1623       */
1624  	public function getItem()
1625      {
1626          return $this->_item;
1627      }
1628  
1629      /**
1630       * @return TControl the control originally raises the <b>Command</b> event.
1631       */
1632  	public function getCommandSource()
1633      {
1634          return $this->_source;
1635      }
1636  }
1637  
1638  /**
1639   * TDataGridSortCommandEventParameter class
1640   *
1641   * TDataGridSortCommandEventParameter encapsulates the parameter data for
1642   * {@link TDataGrid::onSortCommand SortCommand} event of {@link TDataGrid} controls.
1643   *
1644   * The {@link getCommandSource CommandSource} property refers to the control
1645   * that originally raises the OnCommand event, while {@link getSortExpression SortExpression}
1646   * gives the sort expression carried with the sort command.
1647   *
1648   * @author Qiang Xue <qiang.xue@gmail.com>
1649   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1650   * @package System.Web.UI.WebControls
1651   * @since 3.0
1652   */
1653  class TDataGridSortCommandEventParameter extends TEventParameter
1654  {
1655      /**
1656       * @var string sort expression
1657       */
1658      private $_sortExpression='';
1659      /**
1660       * @var TControl original event sender
1661       */
1662      private $_source=null;
1663  
1664      /**
1665       * Constructor.
1666       * @param TControl the control originally raises the <b>OnCommand</b> event.
1667       * @param TDataGridCommandEventParameter command event parameter
1668       */
1669  	public function __construct($source,TDataGridCommandEventParameter $param)
1670      {
1671          $this->_source=$source;
1672          $this->_sortExpression=$param->getCommandParameter();
1673      }
1674  
1675      /**
1676       * @return TControl the control originally raises the <b>OnCommand</b> event.
1677       */
1678  	public function getCommandSource()
1679      {
1680          return $this->_source;
1681      }
1682  
1683      /**
1684       * @return string sort expression
1685       */
1686  	public function getSortExpression()
1687      {
1688          return $this->_sortExpression;
1689      }
1690  }
1691  
1692  /**
1693   * TDataGridPageChangedEventParameter class
1694   *
1695   * TDataGridPageChangedEventParameter encapsulates the parameter data for
1696   * {@link TDataGrid::onPageIndexChanged PageIndexChanged} event of {@link TDataGrid} controls.
1697   *
1698   * The {@link getCommandSource CommandSource} property refers to the control
1699   * that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
1700   * returns the new page index carried with the page command.
1701   *
1702   * @author Qiang Xue <qiang.xue@gmail.com>
1703   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1704   * @package System.Web.UI.WebControls
1705   * @since 3.0
1706   */
1707  class TDataGridPageChangedEventParameter extends TEventParameter
1708  {
1709      /**
1710       * @var integer new page index
1711       */
1712      private $_newIndex;
1713      /**
1714       * @var TControl original event sender
1715       */
1716      private $_source=null;
1717  
1718      /**
1719       * Constructor.
1720       * @param TControl the control originally raises the <b>OnCommand</b> event.
1721       * @param integer new page index
1722       */
1723  	public function __construct($source,$newPageIndex)
1724      {
1725          $this->_source=$source;
1726          $this->_newIndex=$newPageIndex;
1727      }
1728  
1729      /**
1730       * @return TControl the control originally raises the <b>OnCommand</b> event.
1731       */
1732  	public function getCommandSource()
1733      {
1734          return $this->_source;
1735      }
1736  
1737      /**
1738       * @return integer new page index
1739       */
1740  	public function getNewPageIndex()
1741      {
1742          return $this->_newIndex;
1743      }
1744  }
1745  
1746  /**
1747   * TDataGridItem class
1748   *
1749   * A TDataGridItem control represents an item in the {@link TDataGrid} control,
1750   * such as heading section, footer section, or a data item.
1751   * The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
1752   * and {@link getDataItem DataItem} properties, respectively. The type of the item
1753   * is given by {@link getItemType ItemType} property. Property {@link getDataSourceIndex DataSourceIndex}
1754   * gives the index of the item from the bound data source.
1755   *
1756   * @author Qiang Xue <qiang.xue@gmail.com>
1757   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1758   * @package System.Web.UI.WebControls
1759   * @since 3.0
1760   */
1761  class TDataGridItem extends TTableRow implements INamingContainer
1762  {
1763      /**
1764       * @var integer index of the data item in the Items collection of datagrid
1765       */
1766      private $_itemIndex='';
1767      /**
1768       * @var integer index of the item from the bound data source
1769       */
1770      private $_dataSourceIndex=0;
1771      /**
1772       * type of the TDataGridItem
1773       * @var string
1774       */
1775      private $_itemType='';
1776      /**
1777       * value of the data item
1778       * @var mixed
1779       */
1780      private $_dataItem=null;
1781  
1782      /**
1783       * Constructor.
1784       * @param integer zero-based index of the item in the item collection of datagrid
1785       * @param TListItemType item type
1786       */
1787  	public function __construct($itemIndex,$dataSourceIndex,$itemType)
1788      {
1789          $this->_itemIndex=$itemIndex;
1790          $this->_dataSourceIndex=$dataSourceIndex;
1791          $this->setItemType($itemType);
1792          if($itemType===TListItemType::Header)
1793              $this->setTableSection(TTableRowSection::Header);
1794          else if($itemType===TListItemType::Footer)
1795              $this->setTableSection(TTableRowSection::Footer);
1796      }
1797  
1798      /**
1799       * @return TListItemType item type.
1800       */
1801  	public function getItemType()
1802      {
1803          return $this->_itemType;
1804      }
1805  
1806      /**
1807       * @param TListItemType item type
1808       */
1809  	public function setItemType($value)
1810      {
1811          $this->_itemType=TPropertyValue::ensureEnum($value,'TListItemType');
1812      }
1813  
1814      /**
1815       * @return integer zero-based index of the item in the item collection of datagrid
1816       */
1817  	public function getItemIndex()
1818      {
1819          return $this->_itemIndex;
1820      }
1821  
1822      /**
1823       * @return integer the index of the datagrid item from the bound data source
1824       */
1825  	public function getDataSourceIndex()
1826      {
1827          return $this->_dataSourceIndex;
1828      }
1829  
1830      /**
1831       * @return mixed data associated with the item
1832       */
1833  	public function getDataItem()
1834      {
1835          return $this->_dataItem;
1836      }
1837  
1838      /**
1839       * @param mixed data to be associated with the item
1840       */
1841  	public function setDataItem($value)
1842      {
1843          $this->_dataItem=$value;
1844      }
1845  
1846      /**
1847       * This method overrides parent's implementation by wrapping event parameter
1848       * for <b>OnCommand</b> event with item information.
1849       * @param TControl the sender of the event
1850       * @param TEventParameter event parameter
1851       * @return boolean whether the event bubbling should stop here.
1852       */
1853  	public function bubbleEvent($sender,$param)
1854      {
1855          if($param instanceof TCommandEventParameter)
1856          {
1857              $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
1858              return true;
1859          }
1860          else
1861              return false;
1862      }
1863  }
1864  
1865  
1866  /**
1867   * TDataGridPager class.
1868   *
1869   * TDataGridPager represents a datagrid pager.
1870   *
1871   * @author Qiang Xue <qiang.xue@gmail.com>
1872   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1873   * @package System.Web.UI.WebControls
1874   * @since 3.0
1875   */
1876  class TDataGridPager extends TPanel implements INamingContainer
1877  {
1878      private $_dataGrid;
1879  
1880      /**
1881       * Constructor.
1882       * @param TDataGrid datagrid object
1883       */
1884  	public function __construct($dataGrid)
1885      {
1886          $this->_dataGrid=$dataGrid;
1887      }
1888  
1889      /**
1890       * This method overrides parent's implementation by wrapping event parameter
1891       * for <b>OnCommand</b> event with item information.
1892       * @param TControl the sender of the event
1893       * @param TEventParameter event parameter
1894       * @return boolean whether the event bubbling should stop here.
1895       */
1896  	public function bubbleEvent($sender,$param)
1897      {
1898          if($param instanceof TCommandEventParameter)
1899          {
1900              $this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
1901              return true;
1902          }
1903          else
1904              return false;
1905      }
1906  
1907      /**
1908       * @return TDataGrid the datagrid owning this pager
1909       */
1910  	public function getDataGrid()
1911      {
1912          return $this->_dataGrid;
1913      }
1914  
1915      /**
1916       * @return string item type.
1917       */
1918  	public function getItemType()
1919      {
1920          return TListItemType::Pager;
1921      }
1922  }
1923  
1924  
1925  /**
1926   * TDataGridItemCollection class.
1927   *
1928   * TDataGridItemCollection represents a collection of data grid items.
1929   *
1930   * @author Qiang Xue <qiang.xue@gmail.com>
1931   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1932   * @package System.Web.UI.WebControls
1933   * @since 3.0
1934   */
1935  class TDataGridItemCollection extends TList
1936  {
1937      /**
1938       * Inserts an item at the specified position.
1939       * This overrides the parent implementation by inserting only TDataGridItem.
1940       * @param integer the speicified position.
1941       * @param mixed new item
1942       * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridItem.
1943       */
1944  	public function insertAt($index,$item)
1945      {
1946          if($item instanceof TDataGridItem)
1947              parent::insertAt($index,$item);
1948          else
1949              throw new TInvalidDataTypeException('datagriditemcollection_datagriditem_required');
1950      }
1951  }
1952  
1953  /**
1954   * TDataGridColumnCollection class.
1955   *
1956   * TDataGridColumnCollection represents a collection of data grid columns.
1957   *
1958   * @author Qiang Xue <qiang.xue@gmail.com>
1959   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
1960   * @package System.Web.UI.WebControls
1961   * @since 3.0
1962   */
1963  class TDataGridColumnCollection extends TList
1964  {
1965      /**
1966       * the control that owns this collection.
1967       * @var TControl
1968       */
1969      private $_o;
1970  
1971      /**
1972       * Constructor.
1973       * @param TDataGrid the control that owns this collection.
1974       */
1975  	public function __construct(TDataGrid $owner)
1976      {
1977          $this->_o=$owner;
1978      }
1979  
1980      /**
1981       * @return TDataGrid the control that owns this collection.
1982       */
1983  	protected function getOwner()
1984      {
1985          return $this->_o;
1986      }
1987  
1988      /**
1989       * Inserts an item at the specified position.
1990       * This overrides the parent implementation by inserting only TDataGridColumn.
1991       * @param integer the speicified position.
1992       * @param mixed new item
1993       * @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridColumn.
1994       */
1995  	public function insertAt($index,$item)
1996      {
1997          if($item instanceof TDataGridColumn)
1998          {
1999              $item->setOwner($this->_o);
2000              parent::insertAt($index,$item);
2001          }
2002          else
2003              throw new TInvalidDataTypeException('datagridcolumncollection_datagridcolumn_required');
2004      }
2005  }
2006  
2007  /**
2008   * TDataGridPagerStyle class.
2009   *
2010   * TDataGridPagerStyle specifies the styles available for a datagrid pager.
2011   *
2012   * @author Qiang Xue <qiang.xue@gmail.com>
2013   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
2014   * @package System.Web.UI.WebControls
2015   * @since 3.0
2016   */
2017  class TDataGridPagerStyle extends TPanelStyle
2018  {
2019      private $_mode=null;
2020      private $_nextText=null;
2021      private $_prevText=null;
2022      private $_buttonCount=null;
2023      private $_position=null;
2024      private $_visible=null;
2025      private $_buttonType=null;
2026  
2027      /**
2028       * @return TDataGridPagerMode pager mode. Defaults to TDataGridPagerMode::NextPrev.
2029       */
2030  	public function getMode()
2031      {
2032          return $this->_mode===null?TDataGridPagerMode::NextPrev : $this->_mode;
2033      }
2034  
2035      /**
2036       * @param TDataGridPagerMode pager mode.
2037       */
2038  	public function setMode($value)
2039      {
2040          $this->_mode=TPropertyValue::ensureEnum($value,'TDataGridPagerMode');
2041      }
2042  
2043      /**
2044       * @return TDataGridPagerButtonType the type of command button. Defaults to TDataGridPagerButtonType::LinkButton.
2045       */
2046  	public function getButtonType()
2047      {
2048          return $this->_buttonType===null?TDataGridPagerButtonType::LinkButton:$this->_buttonType;
2049      }
2050  
2051      /**
2052       * @param TDataGridPagerButtonType the type of command button
2053       */
2054  	public function setButtonType($value)
2055      {
2056          $this->_buttonType=TPropertyValue::ensureEnum($value,'TDataGridPagerButtonType');
2057      }
2058  
2059      /**
2060       * @return string text for the next page button. Defaults to '>'.
2061       */
2062  	public function getNextPageText()
2063      {
2064          return $this->_nextText===null?'>':$this->_nextText;
2065      }
2066  
2067      /**
2068       * @param string text for the next page button.
2069       */
2070  	public function setNextPageText($value)
2071      {
2072          $this->_nextText=$value;
2073      }
2074  
2075      /**
2076       * @return string text for the previous page button. Defaults to '<'.
2077       */
2078  	public function getPrevPageText()
2079      {
2080          return $this->_prevText===null?'<':$this->_prevText;
2081      }
2082  
2083      /**
2084       * @param string text for the next page button.
2085       */
2086  	public function setPrevPageText($value)
2087      {
2088          $this->_prevText=$value;
2089      }
2090  
2091      /**
2092       * @return integer maximum number of pager buttons to be displayed. Defaults to 10.
2093       */
2094  	public function getPageButtonCount()
2095      {
2096          return $this->_buttonCount===null?10:$this->_buttonCount;
2097      }
2098  
2099      /**
2100       * @param integer maximum number of pager buttons to be displayed
2101       * @throws TInvalidDataValueException if the value is less than 1.
2102       */
2103  	public function setPageButtonCount($value)
2104      {
2105          if(($value=TPropertyValue::ensureInteger($value))<1)
2106              throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid');
2107          $this->_buttonCount=$value;
2108      }
2109  
2110      /**
2111       * @return TDataGridPagerPosition where the pager is to be displayed. Defaults to TDataGridPagerPosition::Bottom.
2112       */
2113  	public function getPosition()
2114      {
2115          return $this->_position===null?TDataGridPagerPosition::Bottom:$this->_position;
2116      }
2117  
2118      /**
2119       * @param TDataGridPagerPosition where the pager is to be displayed.
2120       */
2121  	public function setPosition($value)
2122      {
2123          $this->_position=TPropertyValue::ensureEnum($value,'TDataGridPagerPosition');
2124      }
2125  
2126      /**
2127       * @return boolean whether the pager is visible. Defaults to true.
2128       */
2129  	public function getVisible()
2130      {
2131          return $this->_visible===null?true:$this->_visible;
2132      }
2133  
2134      /**
2135       * @param boolean whether the pager is visible.
2136       */
2137  	public function setVisible($value)
2138      {
2139          $this->_visible=TPropertyValue::ensureBoolean($value);
2140      }
2141  
2142      /**
2143       * Resets the style to the original empty state.
2144       */
2145  	public function reset()
2146      {
2147          parent::reset();
2148          $this->_visible=null;
2149          $this->_position=null;
2150          $this->_buttonCount=null;
2151          $this->_prevText=null;
2152          $this->_nextText=null;
2153          $this->_mode=null;
2154          $this->_buttonType=null;
2155      }
2156  
2157      /**
2158       * Copies the fields in a new style to this style.
2159       * If a style field is set in the new style, the corresponding field
2160       * in this style will be overwritten.
2161       * @param TStyle the new style
2162       */
2163  	public function copyFrom($style)
2164      {
2165          parent::copyFrom($style);
2166          if($style instanceof TDataGridPagerStyle)
2167          {
2168              if($style->_visible!==null)
2169                  $this->_visible=$style->_visible;
2170              if($style->_position!==null)
2171                  $this->_position=$style->_position;
2172              if($style->_buttonCount!==null)
2173                  $this->_buttonCount=$style->_buttonCount;
2174              if($style->_prevText!==null)
2175                  $this->_prevText=$style->_prevText;
2176              if($style->_nextText!==null)
2177                  $this->_nextText=$style->_nextText;
2178              if($style->_mode!==null)
2179                  $this->_mode=$style->_mode;
2180              if($style->_buttonType!==null)
2181                  $this->_buttonType=$style->_buttonType;
2182          }
2183      }
2184  
2185      /**
2186       * Merges the style with a new one.
2187       * If a style field is not set in this style, it will be overwritten by
2188       * the new one.
2189       * @param TStyle the new style
2190       */
2191  	public function mergeWith($style)
2192      {
2193          parent::mergeWith($style);
2194          if($style instanceof TDataGridPagerStyle)
2195          {
2196              if($this->_visible===null)
2197                  $this->_visible=$style->_visible;
2198              if($this->_position===null)
2199                  $this->_position=$style->_position;
2200              if($this->_buttonCount===null)
2201                  $this->_buttonCount=$style->_buttonCount;
2202              if($this->_prevText===null)
2203                  $this->_prevText=$style->_prevText;
2204              if($this->_nextText===null)
2205                  $this->_nextText=$style->_nextText;
2206              if($this->_mode===null)
2207                  $this->_mode=$style->_mode;
2208              if($this->_buttonType===null)
2209                  $this->_buttonType=$style->_buttonType;
2210          }
2211      }
2212  }
2213  
2214  
2215  /**
2216   * TDataGridPagerMode class.
2217   * TDataGridPagerMode defines the enumerable type for the possible modes that a datagrid pager can take.
2218   *
2219   * The following enumerable values are defined:
2220   * - NextPrev: pager buttons are displayed as next and previous pages
2221   * - Numeric: pager buttons are displayed as numeric page numbers
2222   *
2223   * @author Qiang Xue <qiang.xue@gmail.com>
2224   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
2225   * @package System.Web.UI.WebControls
2226   * @since 3.0.4
2227   */
2228  class TDataGridPagerMode extends TEnumerable
2229  {
2230      const NextPrev='NextPrev';
2231      const Numeric='Numeric';
2232  }
2233  
2234  
2235  /**
2236   * TDataGridPagerButtonType class.
2237   * TDataGridPagerButtonType defines the enumerable type for the possible types of datagrid pager buttons.
2238   *
2239   * The following enumerable values are defined:
2240   * - LinkButton: link buttons
2241   * - PushButton: form submit buttons
2242   *
2243   * @author Qiang Xue <qiang.xue@gmail.com>
2244   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
2245   * @package System.Web.UI.WebControls
2246   * @since 3.0.4
2247   */
2248  class TDataGridPagerButtonType extends TEnumerable
2249  {
2250      const LinkButton='LinkButton';
2251      const PushButton='PushButton';
2252  }
2253  
2254  
2255  /**
2256   * TDataGridPagerPosition class.
2257   * TDataGridPagerPosition defines the enumerable type for the possible positions that a datagrid pager can be located at.
2258   *
2259   * The following enumerable values are defined:
2260   * - Bottom: pager appears only at the bottom of the data grid.
2261   * - Top: pager appears only at the top of the data grid.
2262   * - TopAndBottom: pager appears on both top and bottom of the data grid.
2263   *
2264   * @author Qiang Xue <qiang.xue@gmail.com>
2265   * @version $Id: TDataGrid.php 1520 2006-11-27 03:17:58Z xue $
2266   * @package System.Web.UI.WebControls
2267   * @since 3.0.4
2268   */
2269  class TDataGridPagerPosition extends TEnumerable
2270  {
2271      const Bottom='Bottom';
2272      const Top='Top';
2273      const TopAndBottom='TopAndBottom';
2274  }
2275  
2276  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7