SerialColumn.php 636 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\grid;
  8. /**
  9. * SerialColumn displays a column of row numbers (1-based).
  10. *
  11. * @author Qiang Xue <[email protected]>
  12. * @since 2.0
  13. */
  14. class SerialColumn extends Column
  15. {
  16. public $header = '#';
  17. /**
  18. * @inheritdoc
  19. */
  20. protected function renderDataCellContent($model, $key, $index)
  21. {
  22. $pagination = $this->grid->dataProvider->getPagination();
  23. if ($pagination !== false) {
  24. return $pagination->getOffset() + $index + 1;
  25. } else {
  26. return $index + 1;
  27. }
  28. }
  29. }