2016-06-03 3 views
1

У меня возникла проблема при выполнении поиска продукта обновить всю страницу, но я хочу, чтобы при выполнении поиска только listview обновляется, так как в левой части я выполняю другие операции, теперь, при выполнении разбиения на страницы pjax хорошо работает здесь, это код и изображение представления.Как обновить только listview при поиске с помощью Pjax Yii2

В _search.php

<div class="producto-search"> 
<?php \yii\widgets\Pjax::begin(['timeout' => 30000, 'clientOptions' => ['container' => 'pjax-container']]); ?> 

<?php $form = ActiveForm::begin([ 
    'action' => ['index'], 
    'method' => 'get', 
]); ?> 
     <?php 
     $rows = Producto::autocomplete(); 
     $data = ArrayHelper::getColumn($rows, 'NombreProducto'); 
     ?> 
     <?= $form->field($model, 'NombreProducto',[ 
      'template' => '<div class="col-lg-8"><div class="input-group"><span class="input-group-addon"><i class="fa fa-search"></i></span>{input}</div></div>' 
     ]) 
       ->label(false) 
       ->widget(\yii\jui\AutoComplete::classname(),[ 
        'model'=>$model, 
        'attribute'=>'NombreProducto', 
        'options'=>[ 
        'id'=>'busqueda', 
        'class'=>'form-control' 
        ], 
        'clientOptions'=>[ 
        'source'=>$data, 
        'autofill'=>true, 
        'limit'=>'10', 
        'minLength'=>'3', 
        'select' => new JsExpression("function(event, ui) { 
        $('#NombreProducto').val(ui.item.id); 
        }") 
        ], 
        ]);?> 

      <?= Html::submitButton('Buscar', ['class' => 'btn btn-primary pull-left']) ?> 
    <div class="col-lg-2 pull-right"> 
     <?php 
      echo ButtonDropdown::widget([ 
       'label' => 'Categorias', 
       'dropdown' => [ 
        'items' => [ 
         ['label' => 'Alimentos y Bebidas', 'url' => '#'], 
         ['label' => 'Aseo y Hogar', 'url' => '#'], 
         ['label' => 'Bebé', 'url' => '#'], 
         ['label' => 'Cuidado en Casa', 'url' => '#'], 
         ['label' => 'Cuidado Personal', 'url' => '#'], 
         ['label' => 'Dermocosmética', 'url' => '#'], 
         ['label' => 'Maquillaje y Accesorios', 'url' => '#'], 
         ['label' => 'Mascotas', 'url' => '#'], 
         ['label' => 'Medicina Formulada', 'url' => '#'], 
         ['label' => 'Naturales', 'url' => '#'], 
         ['label' => 'Salud y Bienestar', 'url' => '#'], 
        ], 
       ], 
      ]); 
     ?> 
    </div> 
<div class="form-group"> 

</div> 

<?php ActiveForm::end(); ?> 
<?php \yii\widgets\Pjax::end(); ?> 

В index.php

<div class="col-lg-8"> 

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

     </div> 

     <!--Boton de categorias--> 

    </div><!--Seccion de Busqueda--><br> 
    <!--Seccion de productos--> 
     <div id="contenedor-productos" class="col-lg-12"> 
     <div class="row"> 
      <div class="container col-lg-12"> 
      <?php \yii\widgets\Pjax::begin(['timeout' => 30000, 'clientOptions' => ['container' => 'pjax-container']]); ?> 

      <?= 
       ListView::widget([ 
       'options'=>[ 
        'class'=>'col-lg-12 list-wrapper inline', 
       ], 

       'dataProvider' => $listDataProvider, 
       'itemView' => function ($model, $key, $index, $widget) { 
        $itemContent = $this->render('_tabla_producto',['model' => $model]); 
        return $itemContent; 
       }, 
       'itemOptions' => [ 

        'tag' => false, 
       ], 
       'summary' => '', 
       'layout' => '{items}{pager}', 

       'pager' => [ 
        'firstPageLabel' => 'Primera', 
        'lastPageLabel' => 'Ultima', 
        'maxButtonCount' => 5, 
        'options' => [ 
         'class' => 'pagination col-xs-12' 
        ] 
       ], 
      ]); 
      ?> 
      <?php \yii\widgets\Pjax::end(); ?> 
      </div> 
     </div> 
     </div> 

В VentaController.php

public function actionIndex() 
{ 
    if (!Yii::$app->user->isGuest /*&& Yii::$app->user->can('Cajero_Ventas_Cotizar')*/) 
    { 
     $model = new Producto; 
     $searchModel = new ProductoSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 
     $modelCliente=new Cliente; 
     $cliente = Cliente::getClientes(); 
     $rows = Producto::autocomplete();//Se envia la variable que contiene los productos a la vista 
      return $this->render('index', array('rows'=>$rows,'model' => $model,'modelC'=>$modelCliente, 'searchModel' => $searchModel,'clientes'=>$cliente, 'listDataProvider' => $dataProvider)); 

    }else{ 
     return $this->render('//site/error', array('name' => '403 Acceso Denegado' , 'message' => "Usted no tiene permisos para realizar la accion.")); 
    } 
} 

view

ответ

2

Я установил ее, добавив свойство

'options' => ['data-pjax' => true ], 

к компоненту ActiveForm