From b596eb1d1bedd9d957b21337ad148b76fd3afc93 Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Thu, 19 Jul 2018 08:12:10 +0530 Subject: [PATCH] more fixes on datagrid --- .../ViewComposers/DataGrids/UserComposer.php | 15 ++++++++ packages/Webkul/Ui/src/DataGrid/DataGrid.php | 35 ++++++++++++++++--- .../Resources/views/datagrid/index.blade.php | 17 +++++---- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php b/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php index 86cc07a40..3fbdbf1ba 100644 --- a/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php +++ b/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php @@ -42,6 +42,21 @@ class UserComposer 'select' => 'u.id', 'aliased' => true , //boolean to validate aliasing on the basis of this. 'filterable' => [ + [ + 'column' => 'u.email', + 'type' => 'string', + 'label' => 'Admin E-Mail' + ], [ + 'column' => 'u.name', + 'type' => 'string', + 'label' => 'Admin Name' + ], [ + 'column' => 'u.id', + 'type' => 'number', + 'label' => 'Admin ID' + ] + ], + 'searchable' => [ [ 'column' => 'u.email', 'type' => 'string', diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 9d4c1bb28..368c4e087 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -88,9 +88,9 @@ class DataGrid { // list($name, $select, $table, $join, $columns) = array_values($args); $name = $select = $aliased = $table = false; - $join = $columns = $filterable = $css = $operators = []; + $join = $columns = $filterable = $searchable = $css = $operators = []; extract($args); - return $this->build($name, $select, $filterable, $aliased, $table, $join, $columns, $css, $operators); + return $this->build($name, $select, $filterable, $searchable, $aliased, $table, $join, $columns, $css, $operators); } //starts buikding the queries on the basis of selects, joins and filter with @@ -100,6 +100,7 @@ class DataGrid $name = null, $select = false, array $filterable = [], + array $searchable = [], bool $aliased = false, $table = null, array $join = [], @@ -109,10 +110,10 @@ class DataGrid Pagination $pagination = null ) { $this->request = Request::capture(); - $this->setName($name); $this->setSelect($select); $this->setFilterable($filterable); + $this->setSearchable($filterable); $this->setAlias($aliased); $this->setTable($table); $this->setJoin($join); @@ -158,6 +159,16 @@ class DataGrid return $this; } + /** + * Set Searchable columns + * @return $this + */ + + public function setSearchable($searchable) { + $this->searchable = $searchable ?: []; + return $this; + } + /** * Set alias parameter * to know whether @@ -384,7 +395,7 @@ class DataGrid foreach ($parsed as $k=>$v) { parse_str($v, $parsed[$k]); } - + // dump($parsed); foreach ($parsed as $key => $value) { foreach ($value as $column => $filter) { if (array_keys($filter)[0]=="like") { @@ -398,7 +409,21 @@ class DataGrid str_replace('_', '.', $column), //replace the logic of making the column name and consider the case for _ array_values($filter)[0] ); - } else { + } + else if($column == "search") { + foreach($this->searchable as $search) + { + // dump($search['column'],array_values($filter)[0]); + $this->query->orWhere( + $search['column'], + $this->operators['like'], + '%'.array_values($filter)[0].'%' + ); + // $this->results = $this->query->get(); + // dd($this->results); + } + } + else { $this->query->where( str_replace('_', '.', $column), $this->operators[array_keys($filter)[0]], diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php index cb406f1f9..a86a2c25e 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php @@ -109,9 +109,7 @@
- {{-- {{ $columns }}
- {{ json_encode($operators) }} --}} - + {{-- Stock @@ -119,7 +117,7 @@ Available - + --}}
@@ -160,7 +158,7 @@ @section('javascript')