more fixes on datagrid

This commit is contained in:
Prashant Singh 2018-07-19 08:12:10 +05:30
parent efa1e8b716
commit b596eb1d1b
3 changed files with 55 additions and 12 deletions

View File

@ -42,6 +42,21 @@ class UserComposer
'select' => 'u.id',
'aliased' => true , //boolean to validate aliasing on the basis of this.
'filterable' => [
[
'column' => 'u.email',
'type' => 'string',
'label' => 'Admin E-Mail'
], [
'column' => 'u.name',
'type' => 'string',
'label' => 'Admin Name'
], [
'column' => 'u.id',
'type' => 'number',
'label' => 'Admin ID'
]
],
'searchable' => [
[
'column' => 'u.email',
'type' => 'string',

View File

@ -88,9 +88,9 @@ class DataGrid
{
// list($name, $select, $table, $join, $columns) = array_values($args);
$name = $select = $aliased = $table = false;
$join = $columns = $filterable = $css = $operators = [];
$join = $columns = $filterable = $searchable = $css = $operators = [];
extract($args);
return $this->build($name, $select, $filterable, $aliased, $table, $join, $columns, $css, $operators);
return $this->build($name, $select, $filterable, $searchable, $aliased, $table, $join, $columns, $css, $operators);
}
//starts buikding the queries on the basis of selects, joins and filter with
@ -100,6 +100,7 @@ class DataGrid
$name = null,
$select = false,
array $filterable = [],
array $searchable = [],
bool $aliased = false,
$table = null,
array $join = [],
@ -109,10 +110,10 @@ class DataGrid
Pagination $pagination = null
) {
$this->request = Request::capture();
$this->setName($name);
$this->setSelect($select);
$this->setFilterable($filterable);
$this->setSearchable($filterable);
$this->setAlias($aliased);
$this->setTable($table);
$this->setJoin($join);
@ -158,6 +159,16 @@ class DataGrid
return $this;
}
/**
* Set Searchable columns
* @return $this
*/
public function setSearchable($searchable) {
$this->searchable = $searchable ?: [];
return $this;
}
/**
* Set alias parameter
* to know whether
@ -384,7 +395,7 @@ class DataGrid
foreach ($parsed as $k=>$v) {
parse_str($v, $parsed[$k]);
}
// dump($parsed);
foreach ($parsed as $key => $value) {
foreach ($value as $column => $filter) {
if (array_keys($filter)[0]=="like") {
@ -398,7 +409,21 @@ class DataGrid
str_replace('_', '.', $column), //replace the logic of making the column name and consider the case for _
array_values($filter)[0]
);
} else {
}
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 {
$this->query->where(
str_replace('_', '.', $column),
$this->operators[array_keys($filter)[0]],

View File

@ -109,9 +109,7 @@
</div>
</div>
<div class="filter-row-two">
{{-- {{ $columns }}<br/>
{{ json_encode($operators) }} --}}
<span class="filter-one">
{{-- <span class="filter-one">
<span class="filter-name">
Stock
</span>
@ -119,7 +117,7 @@
Available
<span class="icon cross-icon"></span>
</span>
</span>
</span> --}}
</div>
</div>
<div class="table">
@ -160,7 +158,7 @@
@section('javascript')
<script type="text/javascript">
var allFilters1 = [];
var filter_value;
var search_value;
var filter_column;
var filter_condition;
var filter_range;
@ -184,7 +182,11 @@
}
}
$('.search-btn').click(function(){
filter_value = $(".search-field").val();
search_value = $(".search-field").val();
formURL('search','all',search_value,params); //format for search
alert(search_value);
});
$('.grid_head').on('click', function(){
@ -192,8 +194,10 @@
var currentSort = $(this).data('column-sort');
if(currentSort == "asc"){
$(this).data('column-name','desc');
formURL(column,'sort','desc',params);
}else{
$(this).data('column-name','asc');
formURL(column,'sort','asc',params);
}
});
@ -292,7 +296,6 @@
allFilters1.splice(id,1);
makeURL(allFilters1);
}
console.log(allFilters1);
});
});