Hello community,
i would like to filter my gridview by writing something in the column field but I don’t know how. I have the here the two code snippets: documents and documentsSearch.
Thanks in advance!
documents:
<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use kartik\grid\GridView;
use kartik\export\ExportMenu;
use kartik\daterange\DateRangePicker;
$this->title = 'Dokumente';
//$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row">
<p><div class="col-md-12">
<?php echo $this->render('_search',['dataProvider' => $dataProvider, 'searchModel' => $searchModel,]);
?>
<p><p></div>
<div class="col-md-12">
<div class="documents-index">
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'resizableColumns'=>true,
//'rowOptions' => function ($model, $key, $index, $grid) {
// return [
// 'id' => $model['dre'],
// 'onclick' => exec('H:\kkh\dll\...'),
// ];
//},
'condensed' => true,
'pjax'=>false,
'pjaxSettings'=>[
'neverTimeout'=>true,
],
'hover'=>true,
'toolbar' => [
'content' => '',
'{export}',
],
'export'=>[
'fontAwesome'=>true
],
'toggleDataContainer' => ['class' => 'btn-group-sm'],
'exportContainer' => ['class' => 'btn-group-sm'],
'exportConfig' => [
GridView::CSV => ['label' => 'Als CSV speichern'],
GridView::EXCEL => ['label' => 'Als Excel speichern'],
],
'columns' => [
[
'attribute' => 'fallnr',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'name' ,
'hAlign'=>'left',
'vAlign'=>'middle',
'headerOptions' => ['style' => 'width:20%'],
'value' => function ($data) { return $data['name'] . ', ' . $data['vorname']; }
],
[
'attribute' => 'entlassung',
'hAlign'=>'left',
'vAlign'=>'middle',
'value' => function ($data) {
if ( strpos($data['entlassung'],'2099') !== false) {
return null;
}
else {
return $data['entlassung'];
}
},
'format' => ['datetime', 'php:d.m.Y'],
],
[
'attribute' => 'fach',
'hAlign'=>'left',
'vAlign'=>'middle',
//'filterType' => GridView::FILTER_SELECT2,
//'filterInputOptions' => [
//'placeholder' => 'Alle',
//'id' => 'fach',
//]
],
[
'attribute' => 'station',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'typ',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'status',
'format' => 'html',
'vAlign'=>'middle',
'hAlign'=>'center',
'filter'=> [ "-99" => 'Storniert',"0"=>'Nicht freigegeben',"1"=>'Freigegeben',"1000" =>'In bearbeitung',
"300" =>'Archiviert'],
'value' => function ($data) {
if ($data['status'] == "-99") {
return '<strong style="color:#6a737b"><i class="glyphicon glyphicon-trash" aria-hidden="true"></i></strong>';
}
elseif ($data['status'] == "0") {
return '<strong style="color:#f58025"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></strong>';
}
elseif ($data['status'] == "1") {
return '<strong style="color:#7bc143"><i class="glyphicon glyphicon-ok" aria-hidden="true"></i></strong>';
}
elseif ($data['status'] == "1000") {
return '<strong style="color:#000000"><i class="glyphicon glyphicon-lock" aria-hidden="true"></i></strong>';
}
elseif (($data['status'] == "300") or ($data['status'] == '200')) {
return '<strong style="color:#000000"><i class="glyphicon glyphicon-archive" aria-hidden="true"></i></strong>';
}
elseif ($data['status'] == "-1") {
return '<strong style="color:#f58025"><i class="glyphicon glyphicon-alert" aria-hidden="true"></i></strong>';
}
},
],
[
'attribute' => 'gedruckt',
'hAlign'=>'left',
'vAlign'=>'middle',
'filter'=> [ "Ja","Nein"],
'format' => ['datetime', 'php:d.m.Y H:i:s'],
],
[
'attribute' => 'freigegeben', //Freigabedatum
'hAlign'=>'left',
'vAlign'=>'middle',
'format' => ['datetime', 'php:d.m.Y H:i:s'],
],
[
'attribute' => 'dicpsr',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'laufzeit',
'hAlign'=>'left',
'vAlign'=>'middle',
'filter'=> [ "> 1 Tag","> 5 Tage","> 10 Tage","> 1 Monat","> 6 Monate"],
],
],
'panel' => [
'before' => ' ',
],
]);
?>
</div>
<div class="col-md-12">
<div class="documents-index">
<?php
//echo $count = $dataProvider->getCount();
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'resizableColumns'=>true,
//'rowOptions' => function ($model, $key, $index, $grid) {
// return [
// 'id' => $model['dre'],
// 'onclick' => exec('H:\kkh\dll\...'),
// ];
//},
'condensed' => true,
'pjax'=>false,
'pjaxSettings'=>[
'neverTimeout'=>true,
],
'hover'=>true,
'toolbar' => [
'content' => '',
'{export}',
],
'export'=>[
'fontAwesome'=>true
],
'toggleDataContainer' => ['class' => 'btn-group-sm'],
'exportContainer' => ['class' => 'btn-group-sm'],
'exportConfig' => [
GridView::CSV => ['label' => 'Als CSV speichern'],
GridView::EXCEL => ['label' => 'Als Excel speichern'],
],
'columns' => [
[
'attribute' => 'station',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'anzahl',
'hAlign'=>'left',
'vAlign'=>'middle',
],
[
'attribute' => 'laufzeitentldauer',
'hAlign'=>'left',
'vAlign'=>'middle',
'filter'=> [ "> 1 Tag","> 5 Tage","> 10 Tage","> 1 Monat","> 6 Monate"],
],
],
'panel' => [
'before' => ' ',
],
]);
?>
</div>
</div>
and the file documentsSearch:
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ArrayDataProvider;
class DocumentsSearch extends Model
{
public $entlassung_von;
public $entlassung_bis;
public $dre;
public $fallnr;
public $name;
public $entlassung;
public $fach;
public $station;
public $typ;
public $status;
public $gedruckt;
public $freigegeben;
public $dicpsr;
public $laufzeit;
public $anlage;
public function init()
{
$entlassung_von = date('d.m.Y');
$entlassung_bis = date('d.m.Y');
}
public function rules()
{
// only fields in rules() are searchable
return [
[['dre','fallnr','name','entlassung','fach','station','typ','status','gedruckt','freigegeben','dicpsr', 'laufzeit'], 'safe'],
];
}
public function attributeLabels()
{
return [
'dre' => 'Dokument Nr.',
'fallnr' => 'Fallnr.',
'name' => 'Name Patient',
'vorname' => 'Vorname',
'entlassung' => 'Entlassd.',
'fach' => 'Fach',
'station' => 'Station',
'typ' => 'Typ',
'status' => 'Status',
'gedruckt' => 'Gedruckt',
'freigegeben' => 'Freigegeben',
'dicpsr' => 'Dik. Arzt',
'laufzeit' => 'Laufzeit von der Entlassung bis zur Freigabe',
];
}
public function search($params)
{
//$query = Model::find();
$documents = Yii::$app->db->createCommand("SELECT distinct dre.dre .... ")
->queryAll();
if ($this->load($params)) {
//$from_date = $this->from_date;
$name = strtolower(trim($this->name));
$fallnr = strtolower(trim($this->fallnr));
$entlassung = strtotime($this->entlassung);
$fach = strtolower(trim($this->fach));
$station = strtolower(trim($this->station));
$typ = strtolower(trim($this->typ));
$status = strtolower(trim($this->status));
$gedruckt = strtolower(trim($this->gedruckt));
$freigegeben = (trim($this->freigegeben));
$anlage = strtolower(trim($this->anlage));
$dicspr = strtolower(trim($this->dicpsr));
$laufzeit = ($this->laufzeit);
$documents = array_filter($documents, function ($role) use ($fallnr,$name,$entlassung,$fach,$station,$typ,$status,
$gedruckt,$freigegeben,$laufzeit)
{
return (
empty($name) || strpos((strtolower(is_object($role) ? $role->name : $role['name'])), $name) !== false and
empty($fallnr) || strpos((strtolower(is_object($role) ? $role->fallnr : $role['fallnr'])), $fallnr) !== false and
empty($entlassung) || strpos((strtolower(is_object($role) ? $role->entlassung : $role['entlassung'])), $entlassung) !== false and
empty($fach) || strpos((strtolower(is_object($role) ? $role->fach : $role['fach'])), $fach) !== false and
empty($station) || strpos((strtolower(is_object($role) ? $role->station : $role['station'])), $station) !== false and
empty($dicpsr) || strpos((strtolower(is_object($role) ? $role->dicpsr : $role['dicpsr'])), $dicpsr) !== false and
empty($typ) || strpos((strtolower(is_object($role) ? $role->typ : $role['typ'])), $typ) !== false and
empty($status) || strpos((strtolower(is_object($role) ? $role->status : $role['status'])), $status) !== false and
empty($gedruckt) || strpos((strtolower(is_object($role) ? $role->gedruckt : $role['gedruckt'])), $gedruckt) !== false and
empty($freigegeben) ||strpos((strtolower(is_object($role) ? $role->freigegeben : $role['freigegeben'])), $freigegeben) !== false and
empty($laufzeit) || strpos((strtolower(is_object($role) ? $role->laufzeit : $role['laufzeit'])), $laufzeit) !== false
);
});
}
$dataProvider = new ArrayDataProvider([
//'query' => $query,
'key' => 'dre',
'allModels' => $documents,
'sort' => [
'defaultOrder' => ['fach' => SORT_ASC],
'attributes' => ['dre','fallnr', 'name', 'vorname', 'entlassung', 'fach', 'station', 'typ', 'status', 'dicpsr','gedruckt', 'freigegeben', 'laufzeit', 'dicpsr'],
],
'pagination' => [
'pageSize' => 30,
],
]);
return $dataProvider;
}
}