Non aliased case bug removed
This commit is contained in:
parent
2e70b577a2
commit
2f3b0179d6
|
|
@ -26,37 +26,29 @@ class UserComposer
|
|||
*/
|
||||
public function compose(View $view)
|
||||
{
|
||||
|
||||
$datagrid = DataGrid::make([
|
||||
'name' => 'Admins',
|
||||
'table' => 'admins as u',
|
||||
'select' => 'u.id',
|
||||
'aliased' => true, //use this with false as default and true in case of joins
|
||||
'table' => 'admins',
|
||||
'select' => 'id',
|
||||
'aliased' => false, //use this with false as default and true in case of joins
|
||||
|
||||
//don't use aliasing in case of filters
|
||||
'filterable' => [
|
||||
[
|
||||
'column' => 'u.name',
|
||||
'column' => 'name',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin Name'
|
||||
], [
|
||||
'column' => 'u.id',
|
||||
'type' => 'number',
|
||||
'label' => 'Admin ID'
|
||||
],
|
||||
[
|
||||
'column' => 'r.id',
|
||||
'type' => 'number',
|
||||
'label' => 'Role ID'
|
||||
]
|
||||
],
|
||||
//don't use aliasing in case of searchables
|
||||
'searchable' => [
|
||||
[
|
||||
'column' => 'u.email',
|
||||
'column' => 'email',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin E-Mail'
|
||||
], [
|
||||
'column' => 'u.name',
|
||||
'column' => 'name',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin Name'
|
||||
]
|
||||
|
|
@ -81,47 +73,35 @@ class UserComposer
|
|||
// ],
|
||||
],
|
||||
'join' => [
|
||||
[
|
||||
'join' => 'leftjoin',
|
||||
'table' => 'roles as r',
|
||||
'primaryKey' => 'u.role_id',
|
||||
'condition' => '=',
|
||||
'secondaryKey' => 'r.id',
|
||||
]
|
||||
// [
|
||||
// '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' => 'u.id',
|
||||
'name' => 'id',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin ID',
|
||||
'sortable' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'u.name',
|
||||
'name' => 'name',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin Name',
|
||||
'sortable' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'u.email',
|
||||
'name' => 'email',
|
||||
'type' => 'string',
|
||||
'label' => 'Admin E-Mail',
|
||||
'sortable' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'r.name as Role Name',
|
||||
'type' => 'string',
|
||||
'label' => 'Role Name',
|
||||
'sortable' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'r.id as Role ID',
|
||||
'type' => 'string',
|
||||
'label' => 'Role ID',
|
||||
'sortable' => true,
|
||||
],
|
||||
// [
|
||||
// 'name' => 'a.first_name',
|
||||
// 'type' => 'string',
|
||||
|
|
@ -158,6 +138,138 @@ class UserComposer
|
|||
// 'css' => []
|
||||
|
||||
]);
|
||||
// $datagrid = DataGrid::make([
|
||||
// 'name' => 'Admins',
|
||||
// 'table' => 'admins as u',
|
||||
// 'select' => 'u.id',
|
||||
// 'aliased' => true, //use this with false as default and true in case of joins
|
||||
|
||||
// //don't use aliasing in case of filters
|
||||
// 'filterable' => [
|
||||
// [
|
||||
// 'column' => 'u.name',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Admin Name'
|
||||
// ], [
|
||||
// 'column' => 'u.id',
|
||||
// 'type' => 'number',
|
||||
// 'label' => 'Admin ID'
|
||||
// ],
|
||||
// [
|
||||
// 'column' => 'r.id',
|
||||
// 'type' => 'number',
|
||||
// 'label' => 'Role ID'
|
||||
// ]
|
||||
// ],
|
||||
// //don't use aliasing in case of searchables
|
||||
// 'searchable' => [
|
||||
// [
|
||||
// 'column' => 'u.email',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Admin E-Mail'
|
||||
// ], [
|
||||
// 'column' => 'u.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' => 'u.id',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Admin ID',
|
||||
// 'sortable' => true,
|
||||
// ],
|
||||
// [
|
||||
// 'name' => 'u.name',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Admin Name',
|
||||
// 'sortable' => true,
|
||||
// ],
|
||||
// [
|
||||
// 'name' => 'u.email',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Admin E-Mail',
|
||||
// 'sortable' => true,
|
||||
// ],
|
||||
// [
|
||||
// 'name' => 'r.name as Role Name',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Role Name',
|
||||
// 'sortable' => true,
|
||||
// ],
|
||||
// [
|
||||
// 'name' => 'r.id as Role ID',
|
||||
// 'type' => 'string',
|
||||
// 'label' => 'Role ID',
|
||||
// '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 '<a href="'.$value.'">' . $object->first_name . '</a>';
|
||||
// // },
|
||||
// // ],
|
||||
|
||||
// ],
|
||||
// 'operators' => [
|
||||
// 'eq' => "=",
|
||||
// 'lt' => "<",
|
||||
// 'gt' => ">",
|
||||
// 'lte' => "<=",
|
||||
// 'gte' => ">=",
|
||||
// 'neqs' => "<>",
|
||||
// 'neqn' => "!=",
|
||||
// 'like' => "like",
|
||||
// 'nlike' => "not like",
|
||||
// ],
|
||||
// // 'css' => []
|
||||
|
||||
// ]);
|
||||
|
||||
$view->with('datagrid', $datagrid);
|
||||
// $view->with('count', $this->users->count());
|
||||
|
|
|
|||
|
|
@ -552,7 +552,8 @@ class DataGrid
|
|||
});
|
||||
|
||||
} else {
|
||||
$column_name = array_keys($value)[0];
|
||||
|
||||
$column_name = $key;
|
||||
|
||||
if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") {
|
||||
foreach ($value as $condition => $filter_value) {
|
||||
|
|
@ -655,16 +656,10 @@ class DataGrid
|
|||
}
|
||||
|
||||
//Check for column filter bags and resolve aliasing
|
||||
|
||||
//run this if there are columns with filter bag
|
||||
$this->getQueryWithColumnFilters();
|
||||
|
||||
if (!empty($parsed)) {
|
||||
|
||||
$this->getQueryWithFilters();
|
||||
|
||||
}
|
||||
|
||||
$this->results = $this->query->get();
|
||||
return $this->results;
|
||||
|
||||
|
|
@ -672,19 +667,10 @@ class DataGrid
|
|||
|
||||
$this->query = DB::table($this->table);
|
||||
|
||||
if (!empty($this->select)) {
|
||||
$this->getSelect();
|
||||
}
|
||||
|
||||
$this->getSelect();
|
||||
$this->getQueryWithColumnFilters();
|
||||
|
||||
$parsed = $this->parse();
|
||||
if (!empty($parsed)) {
|
||||
$this->getQueryWithFilters();
|
||||
} else {
|
||||
|
||||
$this->results = $this->query->get();
|
||||
return $this->results;
|
||||
}
|
||||
$this->results = $this->query->get();
|
||||
return $this->results;
|
||||
|
|
|
|||
Loading…
Reference in New Issue