Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

49 lines
1.0KB

  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. * @author Qiang Xue <qiang.xue@gmail.com>
  24. * @since 2.0
  25. */
  26. class SerialColumn extends Column
  27. {
  28. /**
  29. * @inheritdoc
  30. */
  31. public $header = '#';
  32. /**
  33. * @inheritdoc
  34. */
  35. protected function renderDataCellContent($model, $key, $index)
  36. {
  37. $pagination = $this->grid->dataProvider->getPagination();
  38. if ($pagination !== false) {
  39. return $pagination->getOffset() + $index + 1;
  40. } else {
  41. return $index + 1;
  42. }
  43. }
  44. }