Grid now tested with joins also but some results with same column names are giving ambigous results

This commit is contained in:
prashant-webkul 2018-07-16 10:32:20 +05:30
parent 84e33e808e
commit 49583162f5
4 changed files with 102 additions and 75 deletions

View File

@ -148,13 +148,13 @@ class DataGridController extends Controller
]
],
'join' => [
// [
// 'join' => 'rightjoin',
// 'table' => 'roles as r',
// 'primaryKey' => 'a.role_id',
// 'condition' => '=',
// 'secondaryKey' => 'r.id',
// ]
[
'join' => 'leftjoin',
'table' => 'posts as p',
'primaryKey' => 'a.id',
'condition' => '=',
'secondaryKey' => 'p.author_id',
]
],
'columns' => [
[
@ -171,13 +171,13 @@ class DataGridController extends Controller
'sortable' => true,
'filterable' => true
],
// [
// 'name' => 'r.name',
// 'type' => 'string',
// 'label' => 'Role Table ID',
// 'sortable' => true,
// 'filterable' => true,
// ],
[
'name' => 'p.content',
'type' => 'string',
'label' => 'Content',
'sortable' => true,
'filterable' => false,
],
[
'name' => 'a.first_name',
'type' => 'string',

View File

@ -37,67 +37,109 @@ class UserComposer
public function compose(View $view)
{
$datagrid = DataGrid::make([
'name' => 'admin',
// 'select' => 'id',
'table' => 'admins as a',
'name' => 'Users',
'table' => 'admins as u',
'select' => 'u.id',
'aliased' => true , //boolean to validate aliasing on the basis of this.
'filterable' => [
[
'column' => 'u.id',
'type' => 'integer'
], [
'column' => 'u.email',
'type' => 'string'
], [
'column' => 'u.name',
'type' => 'string'
]
],
'join' => [
// [
// 'join' => 'leftjoin',
// 'table' => 'roles as r',
// 'primaryKey' => 'a.role_id',
// 'condition' => '=',
// 'secondaryKey' => 'r.id',
// ]
[
'join' => 'leftjoin',
'table' => 'roles as r',
'primaryKey' => 'u.role_id',
'condition' => '=',
'secondaryKey' => 'r.id',
]
],
'columns' => [
[
'name' => 'a.id',
'name' => 'u.id',
'type' => 'string',
'label' => 'Admin ID',
'sortable' => true,
'filterable' => false,
],
[
'name' => 'a.name',
'name' => 'u.name',
'type' => 'string',
'label' => 'Name',
'label' => 'Admin Name',
'sortable' => true,
'filterable' => false,
// 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 '<a href="'.$value.'">' . $object->name . '</a>';
// },
],
[
'name' => 'a.role_id',
'name' => 'u.email',
'type' => 'string',
'label' => 'Admin Role ID',
'label' => 'Admin E-Mail',
'sortable' => true,
'filterable' => false,
],
[
'name' => 'a.email',
'name' => 'r.name',
'type' => 'string',
'label' => 'Admin Email',
'label' => 'Content',
'sortable' => true,
'filterable' => false,
],
[
'name' => 'a.status',
'type' => 'string',
'label' => 'Admin Status',
'sortable' => true,
'filterable' => false,
],
// [
// '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 '<a href="'.$value.'">' . $object->first_name . '</a>';
// },
// ],
],
'select_verbs' => [
0 => "aggregate",
1 => "columns",
2 => "from",
3 => "joins",
4 => "wheres",
5 => "groups",
6 => "havings",
7 => "orders",
8 => "limit",
9 => "offset",
10 => "lock"
],
'operators' => [
'eq' => "=",
'lt' => "<",
'gt' => ">",
'lte' => "<=",
'gte' => ">=",
'neqs' => "<>",
'neqn' => "!=",
'ceq' => "<=>",
'like' => "like",
'likebin' => "like binary",
'ntlike' => "not like",
'ilike' => "ilike",
'regex' => "regexp",
'notregex' => "not regexp",
'simto' => "similar to",
'nsimto' => "not similar to",
'nilike' => "not ilike",
],
// 'css' => []

View File

@ -87,8 +87,8 @@ class DataGrid
public function make($args)
{
// list($name, $select, $table, $join, $columns) = array_values($args);
$name = $select = $filterable = $aliased = $table = false;
$join = $columns = $css = $operators = [];
$name = $select = $aliased = $table = false;
$join = $columns = $filterable = $css = $operators = [];
extract($args);
return $this->build($name, $select, $filterable, $aliased, $table, $join, $columns, $css, $operators);
}
@ -372,7 +372,7 @@ class DataGrid
private function getQueryWithFilters()
{
// the only use case remaining is making and testing the full validation and testing of t\
// the only use case remaining is making and testing the full validation and testing of
// aliased case with alias used in column names also.
if ($this->aliased) {
//n of joins can lead to n number of aliases for columns and neglect the as for columns

View File

@ -1,6 +1,6 @@
<div class="grid-container{{-- $css->datagrid --}}">
<div class="{{ $css->filter }} filter-wrapper">
{{-- <div class="filter-row-one">
<div class="filter-row-one">
<div class="search-filter">
<input type="search" class="control" placeholder="Search Users" />
</div>
@ -55,7 +55,7 @@
<span class="icon cross-icon"></span>
</span>
</span>
</div> --}}
</div>
</div>
<div class="table">
<table class="{{ $css->table }}">
@ -80,21 +80,6 @@
</tbody>
</table>
{{-- @include('ui::partials.pagination') --}}
{{-- <div class="{{ $css->pagination }}" style="margin-top:15px;">
<div class="pagination">
<a class="page-item previous">
<i class="icon angle-right-icon"></i>
</a>
<a class="page-item">1</a>
<a class="page-item" href="#status/6/page/2">2</a>
<a class="page-item active" href="#status/6/page/3">3</a>
<a class="page-item" href="#status/6/page/4">4</a>
<a class="page-item" href="#status/6/page/5">5</a>
<a href="#status/6/page/2" class="page-item next">
<i class="icon angle-left-icon"></i>
</a>
</div>
</div> --}}
</div>
</div>