Hi, I have customized query in my index file. When it is showed into datagrid, the actionColumn (yii or kartik) did not match with the $model->id
.
It started with index 0, while the $model->id
started with 1.
how i customized the actionColumn
with $model->id
?
this is my model search file
public function search($params)
{
//$query = ItemSparepart::find();
$query = (new Query())->select(['its.id', 'its.name', 'its.remark', 'its.listed',
'sum(stock.qty) as qty', 'its.satuan_id', 'satuan.name as satuan_name'])
->from('item_sparepart its')
->leftJoin('stock', 'stock.item_id = its.id')
->leftJoin('satuan', 'satuan.id = its.satuan_id')
->groupBy('stock.item_id');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'listed' => $this->listed,
'qty' => $this->qty,
//'created_by' => $this->created_by,
'created_time' => $this->created_time,
//'updated_by' => $this->updated_by,
'updated_time' => $this->updated_time,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'remark', $this->remark])
->andFilterWhere(['like', 'satuan.name', $this->satuan_id])
->andFilterWhere(['like', 'category_id', $this->category_id]);
return $dataProvider;
}
and this is my index file
<?php
$gridColumns = [
[
'class' => 'kartik\grid\ActionColumn',
'dropdown' => false,
'vAlign'=>'middle',
],
'id',
'name',
['attribute' => 'qty', 'format' => ['decimal', 2], 'hAlign' => 'right'],
['attribute' => 'satuan_id', 'value' => 'satuan_name'],
//'satuan_name',
['attribute' => 'category_id', 'value' => 'category.name'],
[
'class' => 'kartik\grid\BooleanColumn',
'attribute' => 'listed'
],
'remark:ntext',
];
?>
<?= GridView::widget([
'id' => 'kv-grid-item-sparepart',
'dataProvider'=>$dataProvider,
'filterModel'=>$searchModel,
'columns'=>$gridColumns,
'resizableColumns'=>true,
'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
'headerRowOptions'=>['class'=>'kartik-sheet-style'],
'filterRowOptions'=>['class'=>'kartik-sheet-style'],
'pjax'=>true, // pjax is set to always true for this demo
'toolbar' => [
[
'content' =>
Html::button('<i class="fa fa-plus"></i>', [
'value' => Yii::$app->urlManager->createUrl('/item-sparepart/create'),
'class' => 'btn btn-success showModal',
'id' => 'BtnCreateItemSparepart',
'title' => Yii::t('kvgrid', 'Add Item Sparepart'),
]) . ' ' .
Html::a('<i class="fa fa-refresh"></i>', ['/item-sparepart'], [
'class' => 'btn btn-default',
'title'=>Yii::t('kvgrid', 'Reset Grid'),
'data-pjax' => 0,
]),
'options' => ['class' => 'btn-group mr-2']
],
'{export}',
'{toggleData}'
],
'export'=>[
'fontAwesome'=>true
],
// parameters from the demo form
'bordered'=>true,
'striped'=>false,
'condensed'=>true,
'responsive'=>false,
'hover'=>true,
'showPageSummary'=>false,
'panel'=>[
'type'=>GridView::TYPE_PRIMARY,
],
'persistResize'=>false,
'exportConfig'=>$defaultExportConfig,
]); ?>