筛选 YII2 后 Select2 继续加载
Posted
技术标签:
【中文标题】筛选 YII2 后 Select2 继续加载【英文标题】:Select2 keep loading after filter YII2 【发布时间】:2017-09-20 02:42:25 【问题描述】:感谢阅读。我对 select2 有一些问题 - 过滤 gridview Yii2:
Yii2 在我加载页面时渲染 select2:
enter image description here
所以它起作用了,数据被填充了,但是 select2 继续显示加载图标:
enter image description here
这是我的代码,在“名称”列中选择2
<?=GridView::widget([
'id'=>'crud-datatable',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'pjax'=>true,
'pjaxSettings' => ['options' => ['enablePushState' => false]],
'summary' => 'Từ begin đến end/ Tổng totalCount bản ghi',
'columns' => array(
[
'class' => 'kartik\grid\CheckboxColumn',
'width' => '20px',
],
[
'class' => 'kartik\grid\SerialColumn',
'width' => '30px',
],
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'name',
'headerOptions'=>['style'=>'text-align:center'],
'filter'=>\kartik\select2\Select2::widget([
'model' => $searchModel,
'attribute' => 'name',
'data' => \yii\helpers\ArrayHelper::map(\common\models\Catnew::find()->all(), 'name', 'name'),
'theme' => \kartik\select2\Select2::THEME_BOOTSTRAP,
'hideSearch' => false,
'options' => [
'placeholder' => 'Search for name',
]
])
],
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'position',
],
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'active',
],
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'home',
],
[
'class'=>'\kartik\grid\DataColumn',
'attribute'=>'parent',
],
[
'class' => 'kartik\grid\ActionColumn',
'dropdown' => false,
'vAlign'=>'middle',
'urlCreator' => function($action, $model, $key, $index)
return Url::to([$action,'id'=>$key]);
,
'viewOptions'=>['role'=>'modal-remote','title'=>'View','data-toggle'=>'tooltip'],
'updateOptions'=>['role'=>'modal-remote','title'=>'Update', 'data-toggle'=>'tooltip'],
'deleteOptions'=>['role'=>'modal-remote','title'=>'Delete',
'data-confirm'=>false, 'data-method'=>false,
'data-request-method'=>'post',
'data-toggle'=>'tooltip',
'data-confirm-title'=>'Are you sure?',
'data-confirm-message'=>'Are you sure want to delete this item'],
],
),
'toolbar'=> [
['content'=>
html::a('<i class="glyphicon glyphicon-plus"></i>', ['create'],
['role'=>'modal-remote','title'=> 'Create new Catnews','class'=>'btn btn-default']).
Html::a('<i class="glyphicon glyphicon-repeat"></i>', [''],
['data-pjax'=>1, 'class'=>'btn btn-default', 'title'=>'Reset Grid']).
'toggleData'.
'export'
],
],
'striped' => true,
'condensed' => true,
'responsive' => true,
'panel' => [
'type' => 'primary',
'heading' => '<i class="glyphicon glyphicon-list"></i> Catnews listing',
'before'=>'<em>* Resize table columns just like a spreadsheet by dragging the column edges.</em>',
'after'=>BulkButtonWidget::widget([
'buttons'=>Html::a('<i class="glyphicon glyphicon-trash"></i> Delete All',
["bulkdelete"] ,
[
"class"=>"btn btn-danger btn-xs",
'role'=>'modal-remote-bulk',
'data-confirm'=>false, 'data-method'=>false,
'data-request-method'=>'post',
'data-confirm-title'=>'Are you sure?',
'data-confirm-message'=>'Are you sure want to delete this item'
]),
]).
'<div class="clearfix"></div>',
]
])?>
希望你的帮助:)
【问题讨论】:
【参考方案1】:试试这个:
[
'attribute' => 'name',
'value' => \yii\helpers\ArrayHelper::map(\common\models\Catnew::find()->all(), 'name', 'name'),
'filterType' => GridView::FILTER_SELECT2,
'filter' =>\yii\helpers\ArrayHelper::map(\common\models\Catnew::find()->all(), 'name', 'name'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => '...'],
'format' => 'raw'
],
【讨论】:
我正在使用网格视图,并在其中放置了[ 'attribute' => 'Sub_Division_Name', 'filter' => Select2::widget([ 'data' => \yii\helpers\ArrayHelper::map(\common\models\SurveyHescoSubdivision::find()->all(),'id','name'), 'name' => 'Sub_Division_Name', 'options' => [ 'placeholder' => 'Sub Division Name', ], 'theme' => Select2::THEME_DEFAULT, 'pluginOptions' => [ 'allowClear' => true, ], ]), ],
【参考方案2】:
'pjax'=>true 更改为 false 干得好
【讨论】:
以上是关于筛选 YII2 后 Select2 继续加载的主要内容,如果未能解决你的问题,请参考以下文章