SerialColumn.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * To add a SerialColumn to the [[GridView]], add it to the [[GridView::columns|columns]] configuration as follows:
  12. *
  13. * ```php
  14. * 'columns' => [
  15. * // ...
  16. * [
  17. * 'class' => 'yii\grid\SerialColumn',
  18. * // you may configure additional properties here
  19. * ],
  20. * ]
  21. * ```
  22. *
  23. * For more details and usage information on SerialColumn, see the [guide article on data widgets](guide:output-data-widgets).
  24. *
  25. * @author Qiang Xue <qiang.xue@gmail.com>
  26. * @since 2.0
  27. */
  28. class SerialColumn extends Column
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public $header = '#';
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function renderDataCellContent($model, $key, $index)
  38. {
  39. $pagination = $this->grid->dataProvider->getPagination();
  40. if ($pagination !== false) {
  41. return $pagination->getOffset() + $index + 1;
  42. }
  43. return $index + 1;
  44. }
  45. }