index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. use \app\models\base\Comments;
  3. use yii\helpers\Html;
  4. use yii\helpers\Url;
  5. use yii\grid\ActionColumn;
  6. use yii\grid\GridView;
  7. /** @var yii\web\View $this */
  8. /** @var yii\data\ActiveDataProvider $dataProvider */
  9. $this->title = 'Список комментариев';
  10. $this->params['breadcrumbs'][] = $this->title;
  11. ?>
  12. <div class="comments-index">
  13. <?php \yii\widgets\Pjax::begin([
  14. 'timeout'=>5000,
  15. 'enablePushState'=>false
  16. ])?>
  17. <?
  18. // $dataProvider->setSort([
  19. // 'attributes' => [
  20. // 'created_at'
  21. // ]
  22. // ]);
  23. /*
  24. $dataProvider->sort = ['attributes' => [
  25. 'created_at' =>
  26. [
  27. 'asc' => ['created_at' => SORT_ASC],
  28. 'desc' => ['created_at' => SORT_DESC],
  29. 'default' => SORT_DESC
  30. ],
  31. ]];*/
  32. ?>
  33. <?= GridView::widget([
  34. 'dataProvider' => $dataProvider,
  35. 'filterModel' => $searchModel,
  36. 'layout' => "{errors}\n{summary}\n{pager}\n{items}\n{pager}",
  37. 'tableOptions' => ['id'=>'utab', 'class' => 'table table-striped table-bordered table-min'],
  38. 'filterPosition' =>'header',
  39. 'pager' => [
  40. 'prevPageCssClass' => 'page-item',
  41. 'firstPageLabel' => 'Начало',
  42. 'lastPageLabel' => 'Конец',
  43. 'linkOptions' => [ 'class'=>'page-link'],
  44. 'pageCssClass' => 'page-item',
  45. 'disabledListItemSubTagOptions' => ['tag' => 'a', 'class' => 'page-link'],
  46. ],
  47. 'columns' => [
  48. 'created_at',
  49. ['label'=>"Новость","format"=>"raw","value"=>fn($model)=>isset( $model->post->title )?Html::a($model->post->title,$model->post->getUrl(),["target"=>"_blank"]):''],
  50. 'message:ntext',
  51. 'fakename',
  52. 'ip_address',
  53. //['label'=>"user_agent","format"=>"raw","value"=>fn($model)=>isset( $model->user_agent )?$model->user_agent:''],
  54. 'user_agent',
  55. [
  56. 'class' => ActionColumn::className(),
  57. 'template' => '{view}',
  58. 'urlCreator' => function ($action, Comments $model, $key, $index, $column) {
  59. return Url::toRoute([$action, 'id' => $model->id]);
  60. },
  61. 'header'=>"Действия",
  62. 'buttonOptions' => ['class' => 'btn btn-default btn-sm'],
  63. 'contentOptions'=>['style'=>'min-width: 40px;'],
  64. 'options' =>
  65. [
  66. 'class' => 'nowrap',
  67. ],
  68. ],
  69. ],
  70. ]); ?>
  71. <?php \yii\widgets\Pjax::end()?>
  72. </div>
  73. <script>
  74. $('#utab').DataTable({
  75. paging: false,
  76. columnDefs: [
  77. {
  78. orderable: false,
  79. targets: 1
  80. },
  81. {
  82. orderable: false,
  83. targets: 2
  84. },
  85. {
  86. orderable: false,
  87. targets: 6
  88. },
  89. {
  90. orderable: false,
  91. targets: 6
  92. },
  93. {
  94. orderable: false,
  95. targets: 6
  96. },
  97. {
  98. orderable: false,
  99. targets: 6
  100. },
  101. ],
  102. "responsive": true, "lengthChange": false, "autoWidth": false,
  103. // order: [[1, 'desc']]
  104. });
  105. $('.dataTables_length').addClass('bs-select');
  106. </script>
  107. <style>
  108. .table-min td{ max-width:450px; width: auto;}
  109. </style>