【问题标题】:YII2 gridview custom search with ajaxYII2 gridview自定义搜索与ajax
【发布时间】:2016-02-18 05:44:18
【问题描述】:

我正在使用 Yii2.0 搜索功能,如果我们将网格显示为它意味着 ajax 搜索工作正常,但我必须更改布局(见下面的屏幕),我必须从右侧表单使用 ajax 进行搜索。

我也用谷歌搜索,但没有找到相关的。

提前感谢您的帮助。

【问题讨论】:

    标签: ajax search gridview yii2


    【解决方案1】:

    我建议您使用分离的过滤器形式,如本 Yii2 指南中的说明 http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#separate-filter-form

    使用带有(例如:)以下内容的部分视图 _search.php:

    <?php
    
     use yii\helpers\Html;
     use yii\widgets\ActiveForm;
    
    ?>
    
     <div class="post-search">
        <?php $form = ActiveForm::begin([
          'action' => ['index'],
          'method' => 'get',
       ]); ?>
    
      <?= $form->field($model, 'title') ?>
    
      <?= $form->field($model, 'creation_date') ?>
    
      <div class="form-group">
        <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
        <?= Html::submitButton('Reset', ['class' => 'btn btn-default']) ?>
      </div>
    
      <?php ActiveForm::end(); ?>
    </div>
    

    并将其包含在 index.php 视图中,如下所示:

    <?= $this->render('_search', ['model' => $searchModel]) ?>
    

    【讨论】:

      猜你喜欢
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多