public function run()
 {
     if (!$this->model) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'), ['class' => 'alert alert-danger']);
     }
     $hasFileBehavior = false;
     foreach ($this->model->getBehaviors() as $behavior) {
         if (is_a($behavior, FileBehavior::className())) {
             $hasFileBehavior = true;
         }
     }
     if (!$hasFileBehavior) {
         return Html::tag('div', Html::tag('b', Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'), ['class' => 'alert alert-danger']);
     }
     Url::remember(Url::current());
     return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function (File $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>', ['/file/file/delete', 'id' => $model->id], ['title' => Yii::t('yii', 'Delete'), 'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'), 'data-method' => 'post']);
     }]]]]);
 }
    public function run()
    {
        $fileInput = FileInput::widget(['model' => new UploadForm(), 'attribute' => 'file[]', 'options' => $this->options, 'pluginOptions' => $this->pluginOptions]);
        $urlSetOrder = Url::toRoute('/file/file/set-order');
        $urlGetMainFlag = Url::toRoute('/file/file/get-main');
        Yii::$app->view->registerJs(<<<JS
\$('.file-preview-thumbnails').sortable({
    update: function(event, ui) {
            var order = [];
            \$('.file-preview-thumbnails .kv-file-remove:visible').each(function(k, v) {
                if(\$(v).data('key')) {
                    order[k] = \$(v).data('key');
                }
            });

            if(order.length) {
                \$.ajax(
                    '{$urlSetOrder}',
                    {
                        method: "POST",
                        data: {
                            order: order
                        },
                        success: function(data) {
                        }
                    }
                );
            }
        }
});

var loadMainFlag = function() {
    \$.ajax(
        '{$urlGetMainFlag}',
        {
            method: "GET",
            data: {
                id: '{$this->model->id}',
                model: '{$this->model->formName()}'
            },
            success: function(id) {
                if(id !== 0) {
                    \$('.file-preview-frame .jsFileMain[data-key='+id+']').prop('checked', true);
                }
            }
        }
    );
};

loadMainFlag();

JS
);
        return Html::tag('div', $fileInput, ['class' => 'form-group formInput-' . $this->getId()]);
    }