From 2c90d713af85b6af338716d9c2a9efcece24fb5f Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Wed, 8 Aug 2018 11:03:23 +0530 Subject: [PATCH] Datagrid working without dots in the URL, next is to put the validation for valid aliasing if aliasing is used and set true --- .../ViewComposers/DataGrids/UserComposer.php | 120 +----------------- packages/Webkul/Ui/src/DataGrid/DataGrid.php | 36 ++++-- .../Ui/src/Resources/assets/sass/app.scss | 10 +- .../views/datagrid/filters/default.blade.php | 5 +- .../Resources/views/datagrid/index.blade.php | 7 + .../views/datagrid/table/default.blade.php | 16 +-- 6 files changed, 58 insertions(+), 136 deletions(-) diff --git a/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php b/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php index 68c999966..494b2f68a 100644 --- a/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php +++ b/packages/Webkul/Admin/src/Http/ViewComposers/DataGrids/UserComposer.php @@ -27,122 +27,11 @@ class UserComposer public function compose(View $view) { - // $datagrid = DataGrid::make([ - // 'name' => 'Admins', - // 'table' => 'admins', - // 'select' => 'id', - // 'aliased' => false, //use this with false as default and true in case of joins - // 'perpage' => 2, - // //don't use aliasing in case of filters - // 'filterable' => [ - // [ - // 'column' => 'name', - // 'type' => 'string', - // 'label' => 'Admin Name' - // ] - // ], - // //don't use aliasing in case of searchables - // 'searchable' => [ - // [ - // 'column' => 'email', - // 'type' => 'string', - // 'label' => 'Admin E-Mail' - // ], [ - // 'column' => 'name', - // 'type' => 'string', - // 'label' => 'Admin Name' - // ] - // ], - // 'massoperations' =>[ - // [ - // 'route' => route('admin.datagrid.delete'), - // 'method' => 'DELETE', - // 'label' => 'Delete', - // 'type' => 'button', - // ], - // // [ - // // 'route' => route('admin.datagrid.index'), - // // 'method' => 'POST', - // // 'label' => 'View Grid', - // // 'type' => 'select', - // // 'options' =>[ - // // 1 => 'Edit', - // // 2 => 'Set', - // // 3 => 'Change Status' - // // ] - // // ], - // ], - // 'join' => [ - // // [ - // // 'join' => 'leftjoin', - // // 'table' => 'roles as r', - // // 'primaryKey' => 'u.role_id', - // // 'condition' => '=', - // // 'secondaryKey' => 'r.id', - // // ] - // ], - - // //use aliasing on secodary columns if join is performed - // 'columns' => [ - // [ - // 'name' => 'id', - // 'type' => 'string', - // 'label' => 'Admin ID', - // 'sortable' => true, - // ], - // [ - // 'name' => 'name', - // 'type' => 'string', - // 'label' => 'Admin Name', - // 'sortable' => true, - // ], - // [ - // 'name' => 'email', - // 'type' => 'string', - // 'label' => 'Admin E-Mail', - // 'sortable' => true, - // ], - // // [ - // // 'name' => 'a.first_name', - // // 'type' => 'string', - // // 'label' => 'Admin Name', - // // 'sortable' => true, - // // 'filterable' => true, - // // // will create on run time query - // // // 'filter' => [ - // // // 'function' => 'where', // orwhere - // // // 'condition' => ['name', '=', 'Admin'] // multiarray - // // // ], - // // 'attributes' => [ - // // 'class' => 'class-a class-b', - // // 'data-attr' => 'whatever you want', - // // 'onclick' => "window.alert('alert from datagrid column')" - // // ], - // // 'wrapper' => function ($value, $object) { - // // return '' . $object->first_name . ''; - // // }, - // // ], - - // ], - // 'operators' => [ - // 'eq' => "=", - // 'lt' => "<", - // 'gt' => ">", - // 'lte' => "<=", - // 'gte' => ">=", - // 'neqs' => "<>", - // 'neqn' => "!=", - // 'like' => "like", - // 'nlike' => "not like", - // ], - // // 'css' => [] - - // ]); $datagrid = DataGrid::make([ 'name' => 'Admins', 'table' => 'admins as u', 'select' => 'u.id', - 'perpage' => 2, + 'perpage' => 5, 'aliased' => true, //use this with false as default and true in case of joins 'massoperations' =>[ @@ -168,10 +57,12 @@ class UserComposer [ 'type' => 'Delete', 'route' => route('admin.datagrid.delete'), + 'confirm_text' => 'Do you really want to do this?', 'icon' => 'icon trash-icon', ], [ 'type' => 'Edit', 'route' => route('admin.datagrid.delete'), + 'confirm_text' => 'Do you really want to do this?', 'icon' => 'icon pencil-lg-icon', ], ], @@ -254,14 +145,17 @@ class UserComposer 'filterable' => [ [ 'column' => 'u.name', + 'alias' => 'Name', 'type' => 'string', 'label' => 'Admin Name' ], [ 'column' => 'u.id', + 'alias' => 'ID', 'type' => 'number', 'label' => 'Admin ID' ], [ 'column' => 'r.id', + 'alias' => 'Role_ID', 'type' => 'number', 'label' => 'Role ID' ] @@ -296,4 +190,4 @@ class UserComposer $view->with('datagrid', $datagrid); // $view->with('count', $this->users->count()); } -} +} \ No newline at end of file diff --git a/packages/Webkul/Ui/src/DataGrid/DataGrid.php b/packages/Webkul/Ui/src/DataGrid/DataGrid.php index 9c3481b09..0a21347b5 100644 --- a/packages/Webkul/Ui/src/DataGrid/DataGrid.php +++ b/packages/Webkul/Ui/src/DataGrid/DataGrid.php @@ -452,6 +452,22 @@ class DataGrid // dd($this->query); } + /** + * To find the alias + * of the column and + * by taking the column + * name. + * @return string + */ + + public function findAlias($column_alias) { + foreach($this->columns as $column) { + if($column->alias == $column_alias) { + return $column->name; + } + } + } + /** * Parse the URL * and get it ready @@ -528,7 +544,7 @@ class DataGrid if ($key=="sort") { //resolve the case with the column helper class if(substr_count($key,'_') >= 1) - $column_name = str_replace_first('_', '.', $key); + $column_name = $this->findAlias($key); //case that don't need any resolving $count_keys = count(array_keys($value)); @@ -550,8 +566,7 @@ class DataGrid } }); } else { - $column_name = str_replace_first('_', '.', $key); - + $column_name = $this->findAlias($key); if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") { foreach ($value as $condition => $filter_value) { $this->query->where( @@ -602,9 +617,7 @@ class DataGrid throw new \Exception('Multiple Search keys Found, Please Resolve the URL Manually.'); } else { - $column_name = $key; - if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") { foreach ($value as $condition => $filter_value) { $this->query->where( @@ -707,13 +720,15 @@ class DataGrid //Check for column filter bags and resolve aliasing $this->getQueryWithColumnFilters(); + if (!empty($parsed)) { $this->getQueryWithFilters(); } - // $this->results = $this->query->get(); - // return $this->results; + $this->results = $this->query->get(); + $this->results = $this->query->paginate($this->perpage)->appends(request()->except('page')); + return $this->results; } else { @@ -721,12 +736,17 @@ class DataGrid $this->query = DB::table($this->table); $this->getSelect(); + $this->getQueryWithColumnFilters(); + if (!empty($parsed)) { $this->getQueryWithFilters(); } + $this->results = $this->query->get(); + $this->results = $this->query->paginate($this->perpage)->appends(request()->except('page')); + return $this->results; } } @@ -748,4 +768,4 @@ class DataGrid 'actions' => $this->actions, ]); } -} +} \ No newline at end of file diff --git a/packages/Webkul/Ui/src/Resources/assets/sass/app.scss b/packages/Webkul/Ui/src/Resources/assets/sass/app.scss index 058021b05..e42a8ac55 100644 --- a/packages/Webkul/Ui/src/Resources/assets/sass/app.scss +++ b/packages/Webkul/Ui/src/Resources/assets/sass/app.scss @@ -832,7 +832,7 @@ h2 { } .table { thead { - .xyz { + .mass-action-wrapper { display: flex; flex-direction: row; justify-content: flex-start; @@ -852,10 +852,12 @@ h2 { } } tr { - th.sort-head { + th.grid_head { + cursor:pointer; + .sort-down-icon { - margin-left: 8px; - margin-top: -5px; + margin-left: 5px; + margin-top: -3px; vertical-align: middle; cursor: pointer; } diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/filters/default.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/filters/default.blade.php index 5b2153a65..868c5906e 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/filters/default.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/filters/default.blade.php @@ -13,7 +13,7 @@ - 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 2decade2e..363d4c931 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/index.blade.php @@ -391,6 +391,13 @@ } } } + function confirm_click(x){ + if (confirm(x)) { + + } else { + return false; + } + } @endsection diff --git a/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php b/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php index 646b1da2c..507c1394b 100644 --- a/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/datagrid/table/default.blade.php @@ -4,11 +4,11 @@ - + -
+
@@ -90,19 +90,19 @@ @foreach ($columns as $column) @if($column->sortable == "true") - name, ' as ')) + alias, ' as ')) name); ?> data-column-name="{{ $exploded_name[0] }}" @else - data-column-name="{{ $column->name }}" + data-column-name="{{ $column->alias }}" @endif data-column-label="{{ $column->label }}" data-column-sort="asc">{!! $column->sorting() !!} @else - {!! $column->sorting() !!} + {!! $column->sorting() !!} @endif @endforeach @foreach($actions as $action) @@ -125,9 +125,9 @@ @endforeach @foreach($actions as $action) - + - + @endforeach