i want to show data using sqlDataProvider to gridview from different table and calculate it, here my code in siteController.php
public function actionSyahriyah()
{ $searchModel = new SyahriyahSearch();
$db = Yii::$app->db;
$bayar = $db ->createCommand('SELECT sy.no_syahriyah, sy.banyak, sa.nama, sy.tgl, sa.tarif
FROM santri sa, syahriyah sy
WHERE sa.no_induk = sy.no_induk
ORDER BY sy.tgl');
$dataProvider = new SqlDataProvider([
'sql' => $bayar,
'pagination' => [
'pageSize' => 5
],
]);
return $this->render('syahriyah',[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
and this is the gridview:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
'tgl',
'banyak',
],
'export' => false,
]);
?>
You can use dataProvider
<?php
$bayar = $db ->createCommand('SELECT sy.no_syahriyah, sy.banyak, sa.nama, sy.tgl, sa.tarif
FROM santri sa, syahriyah sy
WHERE sa.no_induk = sy.no_induk
ORDER BY sy.tgl');
$dataProvider = new SqlDataProvider([
'sql' => $bayar,
'pagination' => [
'pageSize' => 5
],
],
]);
?>