date operations in datagrid implemented in order grid filters

This commit is contained in:
prashant-webkul 2018-12-07 18:54:58 +05:30
parent 263c23698e
commit 529e0ecd3b
4 changed files with 37 additions and 13 deletions

View File

@ -131,7 +131,7 @@ class OrderDataGrid
], [
'column' => 'or.created_at',
'alias' => 'createdat',
'type' => 'string',
'type' => 'datetime',
'label' => 'Order Date',
],
],

View File

@ -481,6 +481,21 @@ class DataGrid
}
}
/**
* To find the alias
* of the column and
* by taking the column
* name.
* @return string
*/
public function findType($column_alias) {
foreach($this->columns as $column) {
if($column->alias == $column_alias) {
return $column->type;
}
}
}
/**
* Parse the URL
* and get it ready
@ -546,7 +561,6 @@ class DataGrid
*
* @return QueryBuilder object
*/
private function getQueryWithFilters()
{
$parsed = $this->parse();
@ -560,7 +574,7 @@ class DataGrid
//case that don't need any resolving
$count_keys = count(array_keys($value));
if ($count_keys==1) {
if ($count_keys == 1) {
$this->query->orderBy(
str_replace('_', '.', array_keys($value)[0]),
array_values($value)[0]
@ -568,7 +582,7 @@ class DataGrid
} else {
throw new \Exception('Multiple Sort keys Found, Please Resolve the URL Manually');
}
} elseif ($key=="search") {
} elseif ($key == "search") {
$count_keys = count(array_keys($value));
if($count_keys==1)
@ -631,6 +645,8 @@ class DataGrid
} else {
// $column_name = $key;
$column_name = $this->findAlias($key);
$column_type = $this->findType($key);
if (array_keys($value)[0]=="like" || array_keys($value)[0]=="nlike") {
foreach ($value as $condition => $filter_value) {
$this->query->where(
@ -641,11 +657,19 @@ class DataGrid
}
} else {
foreach ($value as $condition => $filter_value) {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
if($column_type == 'datetime') {
$this->query->whereDate(
$column_name,
$this->operators[$condition],
$filter_value
);
} else {
$this->query->where(
$column_name,
$this->operators[$condition],
$filter_value
);
}
}
}
}

View File

@ -106,7 +106,7 @@
border: 2px solid $control-border-color;
border-radius: 3px;
height: 36px;
max-width: 100%;
width: 100%;
display: inline-block;
vertical-align: middle;
-webkit-transition: 0.2s
@ -124,7 +124,7 @@
border: 2px solid #c7c7c7;
border-radius: 3px;
height: 36px;
max-width: 100%;
width: 100%;
display: inline-block;
vertical-align: middle;
-webkit-transition: 0.2s

View File

@ -94,8 +94,8 @@
<li class="filter-response-boolean">
<select class="control response-boolean">
<option selected disabled>Select Value</option>
<option value="1">True</option>
<option value="0">False</option>
<option value="1">True / Active</option>
<option value="0">False / Inactive</option>
</select>
</li>