From d68954a0e59b93756cb863906c1d03c85c2b5bcb Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Thu, 19 Jul 2018 10:48:15 +0530 Subject: [PATCH] Datagrid Search Fixed --- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 29 ++++++-------- .../Resources/views/datagrid/index.blade.php | 38 ++++++++++--------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 368c4e087..4a484efd8 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -164,10 +164,11 @@ class DataGrid * @return $this */ - public function setSearchable($searchable) { + public function setSearchable($searchable) + { $this->searchable = $searchable ?: []; return $this; - } + } /** * Set alias parameter @@ -409,21 +410,15 @@ class DataGrid str_replace('_', '.', $column), //replace the logic of making the column name and consider the case for _ array_values($filter)[0] ); - } - 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 { + } elseif ($column == "search") { + $this->query->where(function ($query) use ($filter){ + foreach ($this->searchable as $search) { + $query->orWhere($search['column'], 'like', '%'.array_values($filter)[0].'%'); + } + + }); + + } 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 a86a2c25e..d5bf56d63 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php @@ -253,6 +253,7 @@ $('.filter-response-number').css('display','inherit'); } + $('.apply-filter').on('click',function(){ params = (new URL(document.location)).search; @@ -278,10 +279,11 @@ }); }); + $('.remove-filter').on('click', function(){ - console.log('removing'); + // console.log('removing'); var id = $(this).parents('.filter-one').attr('id'); - console.log(allFilters1.length); + // console.log(allFilters1.length); if(allFilters1.length == 1){ allFilters1.pop(); @@ -324,7 +326,7 @@ }; allFilters1.push(tmp); } - console.log('Array from URL = ',allFilters1); + // console.log('Array from URL = ',allFilters1); makeTagsTestPrior(); } @@ -332,9 +334,9 @@ var filterRepeat = 0; //make sure the filter or sort param is not duplicate before pushing it into the all filters array if(allFilters1.length!=0) - for(var i = 0;i'+ response +''; @@ -386,25 +389,26 @@ var filt_url = ''; - for(y in x){ + for(y in x) { k = x[y]; - for(z in k){ + for(z in k) { c = k[z]; for(d in c){ - console.log(y); //first element of per which will make the url filter or sort - console.log(z); //name of the column which is needed to be filtered or sorted - console.log(d); //any condition or just sort - console.log(c[d]); //filter value or response + // console.log(y); //first element of per which will make the url filter or sort + // console.log(z); //name of the column which is needed to be filtered or sorted + // console.log(d); //any condition or just sort + // console.log(c[d]); //filter value or response } } - if(y==0) + + if(y == 0) filt_url = filt_url + '?' + y + '=' + z + '[' + d + ']' + '=' + c[d]; else filt_url = filt_url + '&' + y + '=' + z + '[' + d + ']' + '=' + c[d]; } - console.log(filt_url); - console.log(count_filters); + // console.log(filt_url); + // console.log(count_filters); // return false; document.location = filt_url; }