yii2 gridview row css does not get applied after filter -
i have row css on gridview. after use filtering not applied. below view containg gridview
<?php use yii\helpers\html; use yii\grid\gridview; /* @var $this yii\web\view */ /* @var $searchmodel app\models\surveyssearch */ /* @var $dataprovider yii\data\activedataprovider */ $this->title = 'surveys'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="surveys-index"> <h1><?= html::encode($this->title) ?></h1> <?php // echo $this->render('_search', ['model' => $searchmodel]); ?> <p> <?= html::a('create surveys', ['create'], ['class' => 'btn btn-success']) ?> </p> <p> published - available on website<br/> new - created ready publishing. not visible on website.<br/> <span class="red">deleted</span> - flagged deleted. not visible on website. </p> <?= gridview::widget([ 'dataprovider' => $dataprovider, 'filtermodel' => $searchmodel, 'rowoptions' => function ($model, $index, $widget, $grid){ if($model->published0->description == "deleted") return ['class'=>'red']; }, 'columns' => [ ['class' => 'yii\grid\serialcolumn'], //'survey_id', [ 'attribute' => 'name', 'contentoptions'=>['style'=>'width:250px' ] ], 'description:ntext', //'guid', [ 'attribute' =>'published_name', //'value'=>function ($data) { return $data->published0->description;} , 'contentoptions'=>['style'=>'width:100px' ] ], [ 'attribute' => 'survey_type', 'contentoptions'=>['style'=>'width:50px' ] ], [ 'attribute' => 'region_name' , //'value'=>function ($data) { return $data->region->name;} , ], ['class' => 'yii\grid\actioncolumn'], ], ]); ?> </div>
my model class
<?php namespace app\models; use yii; use sammaye\audittrail\loggablebehavior; use sammaye\audittrail\audittrail; /** * model class table "surveys". * * @property integer $survey_id * @property string $name * @property string $description * @property string $guid * @property integer $published * @property string $date_added * @property string $year_acquired * @property string $year_processed * @property string $survey_type * @property string $total_length * @property integer $region_id * @property string $processing_type * @property string $center_point * @property integer $shrink * @property integer $country_id * * @property casestudysurvey[] $casestudysurveys * @property factsheetviews[] $factsheetviews * @property factsheets[] $factsheets * @property factsheetsseismic[] $factsheetsseismics * @property lines[] $lines * @property surveyviews[] $surveyviews * @property countries $country * @property published $published0 * @property regions $region */ class surveys extends \yii\db\activerecord { const deleted = 0; public $region_name; public $published_name; /** * @inheritdoc */ public static function tablename() { return 'surveys'; } /** * @inheritdoc */ public function rules() { return [ [['name', 'survey_type','country_id'], 'required', 'isempty' => function ($value) { return empty($value); } ], [['description'], 'string'], [['published', 'region_id', 'shrink', 'country_id'], 'integer'], [['date_added'], 'safe'], [['total_length'], 'number'], [['name', 'guid'], 'string', 'max' => 255], [['year_acquired', 'year_processed'], 'string', 'max' => 14], [['survey_type', 'processing_type'], 'string', 'max' => 45], [['center_point'], 'string', 'max' => 100] ]; } /** * @inheritdoc */ public function attributelabels() { return [ 'survey_id' => 'survey id', 'name' => 'name', 'description' => 'description', 'guid' => 'guid', 'published' => 'published', 'date_added' => 'date added', 'year_acquired' => 'year acquired', 'year_processed' => 'year processed', 'survey_type' => 'type', 'total_length' => 'total length', 'region_id' => 'region', 'processing_type' => 'processing type', 'center_point' => 'center point', 'shrink' => 'shrink', 'country_id' => 'country', 'region_name' => 'region', 'published_name' => 'published' ]; } /*public function aftersave(){ $prod = new surveys; yii::error(print_r($this,true)); $prod = $this->getdbprod(); $prod->attributes = $this->attributes; if($prod->save()) return parent::aftersave(); return false; }*/ /* public static function getdb() { //yii::error(print_r($this,true)); return \yii::$app->db; }*/ public function behaviors() { return [ //'sammaye\audittrail\loggablebehaviour' /*'loggablebehavior'=> array( 'class' => 'sammaye\audittrail\loggablebehaviour'//'site.vendor.sammaye.audittrail.loggablebehavior', )*/ ]; } /** * @return \yii\db\activequery */ public function getcasestudysurveys() { return $this->hasmany(casestudysurvey::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getfactsheetviews() { return $this->hasmany(factsheetviews::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getfactsheets() { return $this->hasmany(factsheets::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getfactsheetsseismics() { return $this->hasmany(factsheetsseismic::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getlines() { return $this->hasmany(lines::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getsurveyviews() { return $this->hasmany(surveyviews::classname(), ['survey_id' => 'survey_id']); } /** * @return \yii\db\activequery */ public function getcountry() { return $this->hasone(countries::classname(), ['country_id' => 'country_id']); } /** * @return \yii\db\activequery */ public function getpublished0() { return $this->hasone(published::classname(), ['published_id' => 'published']); } /** * @return \yii\db\activequery */ public function getregion() { return $this->hasone(regions::classname(), ['region_id' => 'region_id']); } public function setdeleted(){ $this->published = self::deleted; } }
it working after changed following
'rowoptions' => function ($model, $index, $widget, $grid){ if($model->published == $model::deleted) return ['class'=>'red']; elseif($model->published == $model::new_s) return ['class'=>'new']; },
Comments
Post a Comment