選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SerialColumn.php 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. }