Hello,
I am new to Yii and need help.
I am trying to use GridView with pjax.
The grid is inside tabs, so I need to reload it when a tab is clicked sending the controller different parameters values.
I’ve read posts and tutorials for a day now with no success in understanding things any better.
I have a controller with this function:
....
use app\models\InvoiceDiscountReport;
....
public function actionGetinvoices() {
$company_id = Generic::COMPANY_ID;
$report_type = isset($this->dataBody['report_type'])?$this->dataBody['report_type']:Generic::AP;
$dataProvider = InvoiceDiscountReport::getInvoices($company_id, $report_type, $order_value, $search_value, $iDisplayStart, $iDisplayLength);
return $this->render('dashboard', [
'dataProvider' => $dataProvider,
]);
In the examples I see this:
public function actionIndex()
{
$model = new Countries();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
$model = new Countries(); //reset model
}
$searchModel = new CountriesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'model' => $model,
]);
}
My questions:
-
I don’t use new model, I use ‘use’ so how do I send the searchModel to the view?
-
I don’t use indexAction I want to call this action when a tab is clicked, how do I do this?
My view:
<div id="invoicesGrid">
<?php Pjax::begin() ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'customer',
'invoices',
'amount',
'amount paid',
'discount',
],
]); ?>
<?php Pjax::end() ?>
</div>
My js file:
$.pjax.reload({container:'#invoicesGrid'});
-
How do I send the report_type var to the controller?
-
How do I tell it to use the getInvoices action on the controller?
Very confused here.
Somebody kill me please…