It provides features like sorting, paging and also filtering the data.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\widgets\BaseListView
示例#1
1
    public function run(){

        if($this->is_pjax){
            Pjax::begin($this->pjaxOptions);
        }

        parent::run();

        if($this->isShowForm) {
            echo PageSize::widget([
                'model'     => $this->filterModel,
                'attribute' => $this->attribute,
                'options'   => [
                    'data-pjax' => '0',
                ],
            ]);
        }

        if($this->is_pjax){
            Pjax::end();
        }

        echo ModelCrud::widget([
            'size' => $this->modalSize,
            'updateUrl' => ($this->updateUrl)? $this->updateUrl : Url::to(['update']),
            'createUrl' => ($this->createUrl)? $this->createUrl : Url::to(['create']),
            'updateVerb' => 'post',
            'viewUrl' => Url::to(['view']),
            'viewVerb' => 'post',
            'createVerb' => 'post',
            'modelTitle' => $this->modelTitle,
            'template' => '{view}{update}{create}',
            'modelClass' =>  $this->dataProvider->query->modelClass
        ]);
    }
 /**
  * @inheritdoc
  * @return bool|string
  * @throws Exception
  */
 public function run()
 {
     $model = $this->model;
     if (!$model) {
         return false;
     }
     if (!$model->hasMethod('getLog')) {
         throw new Exception("Attach " . ChangeLogBehavior::className() . " behavior to " . $model::className());
     }
     /**
      * @var ChangeLogBehavior $model
      */
     $logProvider = $model->getLog();
     $view = $this->header;
     $view .= GridView::widget(['dataProvider' => $logProvider, 'columns' => ['log_time:datetime', 'prefix', ['attribute' => 'message', 'content' => function ($item) {
         $messages = unserialize($item['message']);
         if (is_array($messages)) {
             $message = "";
             foreach ($messages as $attr => $changes) {
                 $message .= $attr . ": " . $changes . "<br>";
             }
             return $message;
         }
         return $messages;
     }]]]);
     return $view;
 }
示例#3
0
 /**
  * Inits widget
  */
 public function init()
 {
     parent::init();
     $this->initVisible();
     $this->initSortable();
     //GridViewAsset::register($this->view);
 }
示例#4
0
 public function init()
 {
     parent::init();
     $this->emptyText = Html::t('templete', 'noData');
     $this->summary = Html::t('templete', 'summary');
     $this->getView()->registerCssFile('/css/listStyle.css');
 }
示例#5
0
 public function renderPager()
 {
     // /controller/action -> #!controller/action
     $str = parent::renderPager();
     $str = str_replace('href="/', 'href="#!', $str);
     return $str;
 }
 public function init()
 {
     $this->showHeader = false;
     $this->showFooter = false;
     $this->layout = '{items}';
     $this->columns = [['class' => 'yii\\grid\\DataColumn', 'format' => 'raw', 'value' => function ($post) {
         foreach ($post->postDates as $postDate) {
             if (!isset($first)) {
                 $first = $postDate->PostDate;
             }
             $last = $postDate->PostDate;
         }
         if ($first == $last) {
             $value = $first;
         } else {
             $value = $first . ' &mdash; ' . $last;
         }
         if ($post->PostText) {
             $value = $value . '<br />' . $post->PostText;
         }
         return $value;
     }], ['format' => 'raw', 'value' => function ($post) {
         return '<span class="js-past_vacation_delete grid_delete_icon" data-post-id="' . $post->PostID . '"><i class="fa fa-trash"></i></span>';
     }]];
     parent::init();
 }
示例#7
0
文件: GridView.php 项目: h11Nox/slug
 /**
  * @inheritdoc
  * @return string the rendering result.
  */
 public function renderTableBody()
 {
     if (!$this->showHeader) {
         return parent::renderTableBody();
     }
     $models = array_values($this->dataProvider->getModels());
     $keys = $this->dataProvider->getKeys();
     $rows = [];
     foreach ($models as $index => $model) {
         $key = $keys[$index];
         if ($this->beforeRow !== null) {
             $row = call_user_func($this->beforeRow, $model, $key, $index, $this);
             if (!empty($row)) {
                 $rows[] = $row;
             }
         }
         $rows[] = $this->renderTableRow($model, $key, $index);
         if ($this->afterRow !== null) {
             $row = call_user_func($this->afterRow, $model, $key, $index, $this);
             if (!empty($row)) {
                 $rows[] = $row;
             }
         }
     }
     if (empty($rows)) {
         $colspan = count($this->columns);
         return "\n<tr><td colspan=\"{$colspan}\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
     } else {
         return "\n" . implode("\n", $rows) . "\n</tbody>";
     }
 }
    public function run()
    {
        $confirm = Yii::t('yii', 'Are you sure you want to delete this item?');
        $js = <<<JS
        \$(".delete-button").click(function(){
            var tr = this.closest('tr');
            var url = \$(this).data('url');
            if (confirm("{$confirm}")) {
                \$.ajax({
                    method: "POST",
                    url: url,
                    success: function(data) {
                        if (data) {
                            tr.remove();
                        }
                    }
                });
            }
        });
JS;
        Yii::$app->view->registerJs($js);
        return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
            return Html::a("{$model->name}.{$model->type}", $model->getUrl());
        }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
            return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'delete-button', 'title' => Yii::t('yii', 'Delete'), 'data-url' => Url::to(['/attachments/file/delete', 'id' => $model->id])]);
        }]]]]);
    }
示例#9
0
 public function renderTableRow($model, $key, $index)
 {
     if ($this->filterRow !== null && call_user_func($this->filterRow, $model, $key, $index, $this) === false) {
         return '';
     }
     return parent::renderTableRow($model, $key, $index);
 }
示例#10
0
 public function renderSection($name)
 {
     if ($name == '{tools}') {
         return $this->renderTools();
     } else {
         return parent::renderSection($name);
     }
 }
示例#11
0
 /**
  * @inheritdoc
  */
 public function renderSection($name)
 {
     if (isset($this->pluginSections[$name])) {
         return $this->pluginSections[$name]->run();
     } else {
         return parent::renderSection($name);
     }
 }
示例#12
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->columns)) {
         $this->columns = $this->columns();
     }
     $this->columns = array_merge($this->columns, $this->actions());
     parent::init();
 }
示例#13
0
 public function run()
 {
     parent::run();
     echo '</div>';
     if (!$this->options['ajax']) {
         $this->registerClientScripts();
         DataTablesAsset::register($this->getView());
     }
 }
示例#14
0
 /**
  * @inheritdoc
  */
 public function renderSection($name)
 {
     switch ($name) {
         case '{button}':
             return $this->button;
         default:
             return parent::renderSection($name);
     }
 }
示例#15
0
 public function renderSection($name)
 {
     switch ($name) {
         case '{bulkActions}':
             return $this->renderBulkActions();
         default:
             return parent::renderSection($name);
     }
 }
示例#16
0
 /**
  * @inheritdoc
  */
 public function renderSection($name)
 {
     switch ($name) {
         case "{toolbar}":
             return $this->renderToolbar();
         default:
             return parent::renderSection($name);
     }
 }
示例#17
0
 /**
  * @inheritdoc
  */
 public function renderSection($name)
 {
     switch ($name) {
         case "{pagesizer}":
             return $this->renderPagesizer();
         default:
             return parent::renderSection($name);
     }
 }
示例#18
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (empty($this->columns)) {
         $this->columns = $this->columns();
     }
     if (!isset($this->columns['actions'])) {
         $this->columns['actions'] = ['class' => 'asdfstudio\\admin\\grids\\ActionColumn'];
     }
     parent::init();
 }
示例#19
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $loaderJs = '$(document).ready(function () {
             $(".grid-view-loading").show();
             $(".grid-view-loading").css("display", "block !important");
             $(".grid-view-loading").css("opacity", "1 !important");
     });';
     $this->getView()->registerJs($loaderJs);
     return parent::run();
 }
示例#20
0
 public function init()
 {
     if ($this->modelClass === null) {
         $models = $this->dataProvider->getModels();
         if (($model = reset($models)) instanceof Model) {
             $this->modelClass = $model->classname();
         }
     }
     parent::init();
 }
示例#21
0
 public function init()
 {
     parent::init();
     $this->tableOptions['layoutH'] = $this->layoutH;
     $this->layout = "<div id='w_list_print'>{summary}\n{items}\n{pager}</div>";
     $this->options['class'] = 'pageContent';
     $pagination = new Pagination();
     $this->dataProvider->setPagination($pagination);
     $this->dataProvider->setSort(new Sort());
 }
示例#22
0
 /**
  * Initializes the grid view.
  * This method will initialize required property values and instantiate [[columns]] objects.
  */
 public function init()
 {
     $this->dataColumnClass = DataColumn::className();
     $this->summaryOptions = ['class' => 'summary well well-sm pull-left margin-bottom-10px'];
     $this->layout = '{summary}<div class="clearfix"></div>{pager}{items}{pager}';
     $this->showFooter = true;
     $this->options = ArrayHelper::merge($this->options, ['class' => 'grid-view table-responsive']);
     $this->pager = ['class' => LinkPager::className()];
     parent::init();
 }
示例#23
0
 /**
  * Runs the widget.
  */
 public function run()
 {
     parent::run();
     $view = $this->getView();
     AdminDataTableAsset::register($view);
     $id = $this->options['id'];
     $view->registerJs('var extensions =' . Json::encode($this->datatable_options) . ' ;', View::POS_READY);
     $view->registerJs('$.extend($.fn.dataTableExt.oStdClasses, extensions);', View::POS_READY);
     $view->registerJs('var ' . $id . ' = $(".' . $this->tableDataClass . '").dataTable();', View::POS_READY);
 }
 public static function CreateGridWithDropDownListHeader($dataProvider, $form, $header_model, $arr_header_values)
 {
     $columns_config = [['class' => SerialColumn::className()]];
     $i = 0;
     foreach ($header_model as $key => $value) {
         $columns_config[] = ['header' => $form->field($header_model, $key, ['inputOptions' => ['label' => '']])->dropDownList($arr_header_values), 'attribute' => $i];
         $i++;
     }
     $dynamic_grid_view = GridView::widget(['dataProvider' => $dataProvider, 'columns' => $columns_config]);
     return $dynamic_grid_view;
 }
示例#25
0
 public function init()
 {
     parent::init();
     $this->rowOptions = function ($model, $key, $index, $grid) {
         if ($index % 2 === 0) {
             return ['class' => 'odd'];
         } else {
             return ['class' => 'even'];
         }
     };
 }
示例#26
0
 /**
  * 
  * I overrode it for making header and body separately
  * 
  */
 public function renderItems()
 {
     if (!$this->fixedHeader) {
         return parent::renderItems();
     }
     $content = array_filter([$this->renderCaption(), $this->renderColumnGroup(), $this->showHeader ? $this->renderTableHeader() : false]);
     $header = Html::tag('table', implode("\n", $content), $this->tableOptions);
     $content = array_filter([$this->renderCaption(), $this->renderColumnGroup(), $this->showFooter ? $this->renderTableFooter() : false, $this->renderTableBody()]);
     $body = Html::tag('table', implode("\n", $content), $this->tableOptions2 ?: $this->tableOptions);
     return strtr($this->fixedHeaderTemplate, ['{header}' => $header, '{body}' => $body]);
 }
示例#27
0
 /**
  * Renders interpreter tabs
  * @return string tabs
  */
 protected function renderViews()
 {
     $columns = ArrayHelper::getColumn($this->_relViews, function ($element) {
         return sprintf('%s:raw', $element['label']);
     });
     if ($this->actions) {
         array_push($columns, $this->actions);
     }
     $provider = new \yii\data\ArrayDataProvider(['allModels' => [ArrayHelper::map($this->_relViews, 'label', 'content')]]);
     echo \yii\grid\GridView::widget(['dataProvider' => $provider, 'columns' => $columns, 'layout' => '{items}', 'pager' => false]);
 }
示例#28
0
 protected function getTable()
 {
     $options = ['dataProvider' => $this->dataProvider, 'summary' => '', 'tableOptions' => $this->tableOptions];
     if ($this->columns) {
         $options['columns'] = $this->columns;
     }
     $table = $this->getPjaxBegin();
     $table .= GridView::widget($options);
     $table .= $this->getPjaxEnd();
     return $table;
 }
 public function run()
 {
     $view = $this->getView();
     SortableAsset::register($view);
     $options = '';
     if ($this->sortOptions !== null) {
         $options = Json::encode($this->sortOptions);
     }
     $id = $this->options['id'];
     $view->registerJs("jQuery('#{$id} table tbody').sortable({$options});");
     parent::run();
 }
 public function run()
 {
     foreach ($this->columns as $column) {
         if (property_exists($column, 'enableSorting')) {
             $column->enableSorting = false;
         }
     }
     parent::run();
     $options = ['id' => $this->id, 'action' => $this->sortUrl, 'sortingPromptText' => $this->sortingPromptText, 'sortingFailText' => $this->failText, 'csrfTokenName' => \Yii::$app->request->csrfParam, 'csrfToken' => \Yii::$app->request->csrfToken];
     $options = Json::encode($options);
     $this->view->registerJs("jQuery.SortableGridView({$options});");
 }