DiyActionColumn.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 common\helpers;
  8. use Yii;
  9. use yii\grid\ActionColumn;
  10. use yii\helpers\Html;
  11. use yii\helpers\Url;
  12. /**
  13. * ActionColumn is a column for the [[GridView]] widget that displays buttons for viewing and manipulating the items.
  14. *
  15. * To add an ActionColumn to the gridview, add it to the [[GridView::columns|columns]] configuration as follows:
  16. *
  17. * ```php
  18. * 'columns' => [
  19. * // ...
  20. * [
  21. * 'class' => ActionColumn::className(),
  22. * // you may configure additional properties here
  23. * ],
  24. * ]
  25. * ```
  26. *
  27. * For more details and usage information on ActionColumn, see the [guide article on data widgets](guide:output-data-widgets).
  28. *
  29. * @author Qiang Xue <qiang.xue@gmail.com>
  30. * @since 2.0
  31. */
  32. class DiyActionColumn extends ActionColumn
  33. {
  34. public $header = '操作';
  35. public $headerOptions = ['class' => 'action-column','style'=>'min-width:135px'];
  36. /**
  37. * Initializes the default button rendering callback for single button
  38. * @param string $name Button name as it's written in template
  39. * @param string $iconName The part of Bootstrap glyphicon class that makes it unique
  40. * @param array $additionalOptions Array of additional options
  41. * @since 2.0.11
  42. */
  43. protected function initDefaultButton($name, $iconName, $additionalOptions = [])
  44. {
  45. if (!isset($this->buttons[$name]) && strpos($this->template, '{' . $name . '}') !== false) {
  46. $this->buttons[$name] = function ($url, $model, $key) use ($name, $iconName, $additionalOptions) {
  47. switch ($name) {
  48. case 'view':
  49. $title = Yii::t('yii', 'View');
  50. break;
  51. case 'update':
  52. $title = Yii::t('yii', 'Update');
  53. break;
  54. case 'delete':
  55. $title = Yii::t('yii', 'Delete');
  56. break;
  57. default:
  58. $title = ucfirst($name);
  59. }
  60. $options = array_merge([
  61. 'title' => $title,
  62. 'aria-label' => $title,
  63. 'data-pjax' => '0',
  64. 'class' => 'btn btn-success btn-xs',
  65. 'data-toggle' => 'tooltip',
  66. ], $additionalOptions, $this->buttonOptions);
  67. return Html::a($title, $url, $options);
  68. };
  69. }
  70. }
  71. }