DataGrid filters now restricted to one per one column
This commit is contained in:
parent
21a16b8cf0
commit
238b2fb20c
|
|
@ -11,27 +11,46 @@ use Webkul\Ui\DataGrid\Helpers\Pagination;
|
|||
use Webkul\Ui\DataGrid\Helpers\Css;
|
||||
use URL;
|
||||
|
||||
/**
|
||||
* DataGrid controller
|
||||
*
|
||||
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
|
||||
* &
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
*
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
|
||||
class DataGrid
|
||||
{
|
||||
|
||||
/**
|
||||
* Name of DataGrid
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $name;
|
||||
|
||||
|
||||
/**
|
||||
* select from table(s)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
|
||||
protected $select;
|
||||
|
||||
|
||||
/**
|
||||
* Table
|
||||
* @var Boolean for aliasing
|
||||
*/
|
||||
|
||||
protected $aliased;
|
||||
|
||||
|
||||
/**
|
||||
* Pagination variable
|
||||
* @var String
|
||||
|
|
@ -39,6 +58,7 @@ class DataGrid
|
|||
|
||||
protected $perpage;
|
||||
|
||||
|
||||
/**
|
||||
* Table
|
||||
*
|
||||
|
|
@ -46,6 +66,8 @@ class DataGrid
|
|||
*/
|
||||
|
||||
protected $table;
|
||||
|
||||
|
||||
/**
|
||||
* Join
|
||||
*
|
||||
|
|
@ -60,62 +82,83 @@ class DataGrid
|
|||
* 'callback' => 'not supported yet'
|
||||
* ]
|
||||
*/
|
||||
protected $join;
|
||||
/**
|
||||
|
||||
protected $join;
|
||||
|
||||
|
||||
/**
|
||||
* Collection Object of Column $columns
|
||||
*
|
||||
* @var Collection
|
||||
*/
|
||||
protected $columns;
|
||||
|
||||
/**
|
||||
protected $columns;
|
||||
|
||||
|
||||
/**
|
||||
* array of columns
|
||||
* to be filtered
|
||||
* @var Array
|
||||
*/
|
||||
protected $filterable;
|
||||
|
||||
/**
|
||||
protected $filterable;
|
||||
|
||||
|
||||
/**
|
||||
* array of columns
|
||||
* to be searched
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $searchable;
|
||||
|
||||
/**
|
||||
protected $searchable;
|
||||
|
||||
|
||||
/**
|
||||
* mass operations
|
||||
*
|
||||
* @var Array
|
||||
*/
|
||||
protected $massoperations;
|
||||
|
||||
/**
|
||||
protected $massoperations;
|
||||
|
||||
|
||||
/**
|
||||
* Pagination $pagination
|
||||
*
|
||||
* @var Pagination
|
||||
*/
|
||||
protected $pagination;
|
||||
|
||||
|
||||
protected $pagination;
|
||||
|
||||
|
||||
/**
|
||||
* Css $css
|
||||
*
|
||||
* @var Css
|
||||
*/
|
||||
protected $css;
|
||||
|
||||
/**
|
||||
protected $css;
|
||||
|
||||
|
||||
/**
|
||||
* Actions $action
|
||||
* @var action
|
||||
*/
|
||||
|
||||
protected $actions;
|
||||
|
||||
|
||||
/**
|
||||
* URL parse $parsed
|
||||
* @var parse
|
||||
*/
|
||||
protected $parsed;
|
||||
/*
|
||||
|
||||
protected $parsed;
|
||||
|
||||
|
||||
/*
|
||||
public function __construct(
|
||||
$name = null ,
|
||||
$table = null ,
|
||||
|
|
@ -136,6 +179,7 @@ class DataGrid
|
|||
}
|
||||
*/
|
||||
|
||||
//Prepares the input parameters passed as the configuration for datagrid.
|
||||
public function make($args)
|
||||
{
|
||||
// list($name, $select, $table, $join, $columns) = array_values($args);
|
||||
|
|
@ -146,9 +190,7 @@ class DataGrid
|
|||
return $this->build($name, $select, $filterable, $searchable, $massoperations, $aliased, $perpage, $table, $join, $columns, $css, $operators,$actions);
|
||||
}
|
||||
|
||||
//starts buikding the queries on the basis of selects, joins and filter with
|
||||
//attributes for class names and styles.
|
||||
|
||||
//This assigns the private and public properties of the datagrid classes from make functions
|
||||
public function build(
|
||||
$name = null,
|
||||
$select = false,
|
||||
|
|
@ -647,6 +689,7 @@ class DataGrid
|
|||
$parsed = $this->parse();
|
||||
|
||||
if ($this->aliased==true) {
|
||||
|
||||
//flags
|
||||
$table_alias = false;
|
||||
$join_table_alias = false;
|
||||
|
|
@ -672,6 +715,7 @@ class DataGrid
|
|||
$table_name = trim($exploded[0]);
|
||||
$table_alias = trim($exploded[1]);
|
||||
}
|
||||
|
||||
//Run this if there are any selects priorly.
|
||||
if (!empty($this->select)) {
|
||||
$this->getSelect();
|
||||
|
|
@ -679,8 +723,11 @@ class DataGrid
|
|||
|
||||
//Run this if there are joins
|
||||
if (!empty($this->join)) {
|
||||
|
||||
foreach ($this->join as $join) {
|
||||
|
||||
$name = strtolower($join['join']);
|
||||
|
||||
//Allow joins i.e left or right
|
||||
if ($name=='leftjoin' || $name=='rightjoin') {
|
||||
|
||||
|
|
@ -688,24 +735,31 @@ class DataGrid
|
|||
$primary_key_alias = trim(explode('.', $join['primaryKey'])[0]);
|
||||
|
||||
if ($primary_key_alias == $table_alias) {
|
||||
|
||||
$join_table_alias = explode('as', $join['table']);
|
||||
|
||||
if (isset($join_table_alias)) {
|
||||
|
||||
$alias1 = trim($join_table_alias[1]); //important!!!!!
|
||||
|
||||
//check if the secondary table match column is not having '.' and has proper alias
|
||||
$secondary_join_column = $join['secondaryKey'];
|
||||
if (isset($secondary_join_column)) {
|
||||
|
||||
$exploded_secondary = explode('.', $secondary_join_column);
|
||||
$alias2 = trim($exploded_secondary[0]);
|
||||
|
||||
if ($alias1 == $alias2) {
|
||||
$this->getQueryWithJoin();
|
||||
$alias_proper_secondary = true;
|
||||
} else {
|
||||
throw new \Exception('Aliases of Join table and the secondary key columns do not match');
|
||||
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('Improper aliasing on secondary/join column for join');
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new \Exception('Join/Secondary table alias is not found for join');
|
||||
}
|
||||
|
|
@ -729,6 +783,7 @@ class DataGrid
|
|||
$this->results = $this->query->get();
|
||||
|
||||
$this->results = $this->query->paginate($this->perpage)->appends(request()->except('page'));
|
||||
|
||||
return $this->results;
|
||||
|
||||
} else {
|
||||
|
|
@ -752,12 +807,17 @@ class DataGrid
|
|||
}
|
||||
|
||||
/**
|
||||
* Main Render Function,
|
||||
* it renders views responsible
|
||||
* for loading datagrid.
|
||||
*
|
||||
* @return view
|
||||
*/
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->getDbQueryResults();
|
||||
|
||||
return view('ui::datagrid.index', [
|
||||
'css' => $this->css,
|
||||
'results' => $this->results,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,14 @@
|
|||
|
||||
namespace Webkul\Ui\DataGrid\Helpers;
|
||||
|
||||
/**
|
||||
* AbstractFillable
|
||||
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
abstract class AbstractFillable
|
||||
{
|
||||
{
|
||||
const NO_RESULT = null;
|
||||
|
||||
protected $fillable = [];
|
||||
|
|
@ -43,7 +49,7 @@ abstract class AbstractFillable
|
|||
private function fieldValidate($key, $value, $allowed = ['string', 'integer', 'float', "boolean"], $merge = false)
|
||||
{
|
||||
$error = false;
|
||||
if( in_array($key, $this->fillable) ||
|
||||
if( in_array($key, $this->fillable) ||
|
||||
array_filter(
|
||||
array_keys($this->fillable) , function($value){
|
||||
return gettype($value) === "string";
|
||||
|
|
@ -54,7 +60,7 @@ abstract class AbstractFillable
|
|||
// if($merge){
|
||||
// if(!$this->{$key}) $this->{$key} = [];
|
||||
// $this->{$key}[] = $value;
|
||||
// }else
|
||||
// }else
|
||||
// $this->{$key} = $value;
|
||||
}else{
|
||||
dump(gettype($value));
|
||||
|
|
|
|||
|
|
@ -3,6 +3,16 @@ namespace Webkul\Ui\DataGrid\Helpers;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Column controller
|
||||
*
|
||||
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
|
||||
* &
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
*
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class Column extends AbstractFillable
|
||||
{
|
||||
const SORT = 'sort';
|
||||
|
|
|
|||
|
|
@ -2,8 +2,14 @@
|
|||
|
||||
namespace Webkul\Ui\DataGrid\Helpers;
|
||||
|
||||
/**
|
||||
* Css
|
||||
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class Css extends AbstractFillable
|
||||
{
|
||||
{
|
||||
const NO_RESULT = 'no-class';
|
||||
|
||||
protected $datagrid = 'datagrid';
|
||||
|
|
@ -13,6 +19,10 @@ class Css extends AbstractFillable
|
|||
protected $tbody = 'tbody';
|
||||
protected $tbody_td = 'tbody_td';
|
||||
|
||||
public function __construct($args){
|
||||
parent::__construct($args);
|
||||
}
|
||||
|
||||
protected function setFillable(){
|
||||
$this->fillable = [
|
||||
'datagrid',
|
||||
|
|
@ -23,8 +33,4 @@ class Css extends AbstractFillable
|
|||
'tbody_td',
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct($args){
|
||||
parent::__construct($args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@ namespace Webkul\Ui\DataGrid\Helpers;
|
|||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* MassAction
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class MassAction
|
||||
{
|
||||
public function validateSchemaMassAction($attributes)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,18 @@ namespace Webkul\Ui\DataGrid\Helpers;
|
|||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
|
||||
/**
|
||||
* DataGrid controller
|
||||
*
|
||||
* @author Nikhil Malik <nikhil@webkul.com> @ysmnikhil
|
||||
* &
|
||||
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
|
||||
*
|
||||
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
||||
*/
|
||||
|
||||
class Pagination extends Paginator
|
||||
{
|
||||
{
|
||||
const LIMIT = 20;
|
||||
const OFFSET = 0;
|
||||
const VIEW = '';
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
@section('javascript')
|
||||
<script type="text/javascript">
|
||||
var columns = @json($columns); //referential
|
||||
var allFilters1 = [];
|
||||
var allFilters = [];
|
||||
var search_value;
|
||||
var filter_column;
|
||||
var filter_condition;
|
||||
var filter_range;
|
||||
var filt = '';
|
||||
var count_filters = parseInt(0);
|
||||
var url;
|
||||
var array_start = '[';
|
||||
|
|
@ -24,11 +23,11 @@
|
|||
var selectedColumn = '';
|
||||
var myURL = document.location;
|
||||
let params;
|
||||
$(document).ready(function(){
|
||||
$(document).ready(function() {
|
||||
|
||||
params = (new URL(document.location)).search;
|
||||
if(params.length>0){
|
||||
if(allFilters1.length == 0) {
|
||||
if(params.length>0) {
|
||||
if(allFilters.length == 0) {
|
||||
//call reverse url function
|
||||
arrayFromUrl(params.slice(1,params.length));
|
||||
}
|
||||
|
|
@ -40,8 +39,11 @@
|
|||
|
||||
//controls for header when sorting is done
|
||||
$('.grid_head').on('click', function() {
|
||||
|
||||
var column = $(this).data('column-name');
|
||||
|
||||
var currentSort = $(this).data('column-sort');
|
||||
|
||||
if(currentSort == "asc")
|
||||
formURL("sort",column,"desc",params);
|
||||
else if(currentSort == "desc")
|
||||
|
|
@ -88,7 +90,7 @@
|
|||
$('.filter-condition-dropdown-datetime').css('display','inherit');
|
||||
$('.filter-response-datetime').css('display','inherit');
|
||||
}
|
||||
else if(typeValue == 'number'){
|
||||
else if(typeValue == 'number') {
|
||||
//hide unwanted
|
||||
$('.filter-condition-dropdown-string').css('display','none');
|
||||
$('.filter-condition-dropdown-datetime').css('display','none');
|
||||
|
|
@ -102,35 +104,42 @@
|
|||
|
||||
}
|
||||
|
||||
$('.apply-filter').on('click',function(){
|
||||
$('.apply-filter').on('click',function() {
|
||||
|
||||
params = (new URL(document.location)).search;
|
||||
if(typeValue == 'number'){
|
||||
|
||||
if(typeValue == 'number') {
|
||||
|
||||
var conditionUsed = $('.filter-condition-dropdown-number').find(':selected').val();
|
||||
var response = $('.response-number').val();
|
||||
formURL(selectedColumn,conditionUsed,response,params,col_label);
|
||||
}
|
||||
if(typeValue == 'string'){
|
||||
if(typeValue == 'string') {
|
||||
|
||||
var conditionUsed = $('.filter-condition-dropdown-string').find(':selected').val();
|
||||
var response = $('.response-string').val();
|
||||
formURL(selectedColumn,conditionUsed,response,params,col_label);
|
||||
|
||||
}
|
||||
if(typeValue == 'datetime'){
|
||||
if(typeValue == 'datetime') {
|
||||
|
||||
var conditionUsed = $('.filter-condition-dropdown-datetime').find(':selected').val();
|
||||
var response = $('.response-datetime').val();
|
||||
formURL(selectedColumn,conditionUsed,response,params,col_label);
|
||||
}
|
||||
if(typeValue == 'boolean'){ //use select dropdown with two values true and false
|
||||
if(typeValue == 'boolean') { //use select dropdown with two values true and false
|
||||
|
||||
console.log('boolean');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//remove the filter and from clicking on cross icon on tag
|
||||
$('.remove-filter').on('click', function(){
|
||||
$('.remove-filter').on('click', function() {
|
||||
|
||||
var id = $(this).parents('.filter-one').attr('id');
|
||||
if(allFilters1.length == 1){
|
||||
allFilters1.pop();
|
||||
if(allFilters.length == 1) {
|
||||
allFilters.pop();
|
||||
var uri = window.location.href.toString();
|
||||
if (uri.indexOf("?") > 0) {
|
||||
var clean_uri = uri.substring(0, uri.indexOf("?"));
|
||||
|
|
@ -138,9 +147,9 @@
|
|||
document.location = clean_uri;
|
||||
}
|
||||
}
|
||||
else{
|
||||
allFilters1.splice(id,1);
|
||||
makeURL(allFilters1);
|
||||
else {
|
||||
allFilters.splice(id,1);
|
||||
makeURL(allFilters);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -150,43 +159,57 @@
|
|||
|
||||
// master checkbox for selecting all entries
|
||||
$("input[id=mastercheckbox]").change(function() {
|
||||
if($("input[id=mastercheckbox]").prop('checked') == true){
|
||||
$('.indexers').each(function(){
|
||||
if($("input[id=mastercheckbox]").prop('checked') == true) {
|
||||
$('.indexers').each(function() {
|
||||
this.checked = true;
|
||||
if(this.checked){
|
||||
y = parseInt($(this).attr('id')); id.push(y);
|
||||
}
|
||||
});
|
||||
|
||||
$('.mass-action').css('display','');
|
||||
|
||||
$('.table-grid-header').css('display','none');
|
||||
// $('.selected-items').html(id.toString());
|
||||
|
||||
$('#indexes').val(id);
|
||||
}
|
||||
else if($("input[id=mastercheckbox]").prop('checked') == false) {
|
||||
|
||||
$('.indexers').each(function(){ this.checked = false; });
|
||||
|
||||
id = [];
|
||||
|
||||
$('.mass-action').css('display','none');
|
||||
|
||||
$('.table-grid-header').css('display','');
|
||||
|
||||
$('#indexes').val('');
|
||||
}
|
||||
});
|
||||
|
||||
$('.massaction-remove').on('click', function(){
|
||||
$('.massaction-remove').on('click', function() {
|
||||
|
||||
id = [];
|
||||
|
||||
$('.mass-action').css('display','none');
|
||||
|
||||
if($('#mastercheckbox').prop('checked')) {
|
||||
$('#mastercheckbox').prop('checked',false);
|
||||
}
|
||||
$("input[class=indexers]").each(function(){
|
||||
if($(this).prop('checked')){
|
||||
|
||||
$("input[class=indexers]").each(function() {
|
||||
if($(this).prop('checked')) {
|
||||
$(this).prop('checked',false);
|
||||
}
|
||||
});
|
||||
|
||||
$('.table-grid-header').css('display','');
|
||||
});
|
||||
|
||||
$("input[class=indexers]").change(function() {
|
||||
if(this.checked){
|
||||
|
||||
if(this.checked) {
|
||||
y = parseInt($(this).attr('id'));
|
||||
id.push(y);
|
||||
}
|
||||
|
|
@ -195,6 +218,7 @@
|
|||
var index = id.indexOf(y);
|
||||
id.splice(index,1);
|
||||
}
|
||||
|
||||
if(id.length>0) {
|
||||
|
||||
$('.mass-action').css('display','');
|
||||
|
|
@ -204,7 +228,9 @@
|
|||
}else if(id.length == 0) {
|
||||
|
||||
$('.mass-action').css('display','none');
|
||||
|
||||
$('.table-grid-header').css('display','');
|
||||
|
||||
$('#indexes').val('');
|
||||
|
||||
if($('#mastercheckbox').prop('checked')) {
|
||||
|
|
@ -218,69 +244,118 @@
|
|||
});
|
||||
|
||||
//make the url from the array and redirect
|
||||
function makeURL() {
|
||||
if(allFilters1.length>0)
|
||||
function makeURL(repetition = false) {
|
||||
|
||||
if(allFilters.length>0 && repetition == false)
|
||||
{
|
||||
for(i=0;i<allFilters1.length;i++) {
|
||||
alert('this is here 1');
|
||||
|
||||
for(i=0;i<allFilters.length;i++) {
|
||||
if(i==0){
|
||||
url = '?' + allFilters1[i].column + '[' + allFilters1[i].cond + ']' + '=' + allFilters1[i].val;
|
||||
url = '?' + allFilters[i].column + '[' + allFilters[i].cond + ']' + '=' + allFilters[i].val;
|
||||
}
|
||||
else
|
||||
url = url + '&' + allFilters1[i].column + '[' + allFilters1[i].cond + ']' + '=' + allFilters1[i].val;
|
||||
url = url + '&' + allFilters[i].column + '[' + allFilters[i].cond + ']' + '=' + allFilters[i].val;
|
||||
}
|
||||
document.location = url;
|
||||
|
||||
} else if(allFilters.length>0 && repetition == true) {
|
||||
|
||||
alert('this is here 2');
|
||||
|
||||
//this is the case when the filter is being repeated on a single column with different condition and value
|
||||
for(i=0;i<allFilters.length;i++) {
|
||||
|
||||
if(i==0){
|
||||
url = '?' + allFilters[i].column + '[' + allFilters[i].cond + ']' + '=' + allFilters[i].val;
|
||||
}
|
||||
else
|
||||
url = url + '&' + allFilters[i].column + '[' + allFilters[i].cond + ']' + '=' + allFilters[i].val;
|
||||
}
|
||||
|
||||
document.location = url;
|
||||
|
||||
} else {
|
||||
|
||||
alert('this is here 3');
|
||||
|
||||
var uri = window.location.href.toString();
|
||||
|
||||
var clean_uri = uri.substring(0, uri.indexOf("?"));
|
||||
|
||||
document.location = clean_uri;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//make the filter array from url after being redirected
|
||||
function arrayFromUrl(x) {
|
||||
function arrayFromUrl(urlstring) {
|
||||
|
||||
var obj={};
|
||||
t = x.slice(0,x.length);
|
||||
|
||||
t = urlstring.slice(0,urlstring.length);
|
||||
|
||||
splitted = [];
|
||||
|
||||
moreSplitted = [];
|
||||
|
||||
splitted = t.split('&');
|
||||
|
||||
for(i=0;i<splitted.length;i++) {
|
||||
|
||||
moreSplitted.push(splitted[i].split('='));
|
||||
|
||||
}
|
||||
for(i=0;i<moreSplitted.length;i++) {
|
||||
|
||||
col = moreSplitted[i][0].replace(']','').split('[')[0];
|
||||
|
||||
cond = moreSplitted[i][0].replace(']','').split('[')[1]
|
||||
|
||||
val = moreSplitted[i][1];
|
||||
|
||||
obj.column = col;
|
||||
|
||||
obj.cond = cond;
|
||||
|
||||
obj.val = val;
|
||||
|
||||
if(col!=undefined && cond!=undefined && val!=undefined)
|
||||
allFilters1.push(obj);
|
||||
allFilters.push(obj);
|
||||
|
||||
obj = {};
|
||||
|
||||
}
|
||||
makeTags();
|
||||
}
|
||||
|
||||
//use the label to prevent the display of column name on the body
|
||||
function makeTags() {
|
||||
var filterRepeat = 0;
|
||||
if(allFilters1.length!=0)
|
||||
for(var i = 0;i<allFilters1.length;i++) {
|
||||
if(allFilters1[i].column == "sort") {
|
||||
|
||||
col_label_tag = $('li[data-name="'+allFilters1[i].cond+'"]').text();
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters1[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
var filterRepeat = 0;
|
||||
|
||||
if(allFilters.length!=0)
|
||||
for(var i = 0;i<allFilters.length;i++) {
|
||||
|
||||
if(allFilters[i].column == "sort") {
|
||||
|
||||
col_label_tag = $('li[data-name="'+allFilters[i].cond+'"]').text();
|
||||
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
$('.filter-row-two').append(filter_card);
|
||||
|
||||
} else if(allFilters1[i].column == "search") {
|
||||
} else if(allFilters[i].column == "search") {
|
||||
|
||||
col_label_tag = "Search";
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters1[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
$('.filter-row-two').append(filter_card);
|
||||
|
||||
} else {
|
||||
col_label_tag = $('li[data-name="'+allFilters1[i].column+'"]').text().trim();
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters1[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
|
||||
col_label_tag = $('li[data-name="'+allFilters[i].column+'"]').text().trim();
|
||||
|
||||
var filter_card = '<span class="filter-one" id="'+ i +'"><span class="filter-name">'+ col_label_tag +'</span><span class="filter-value"><span class="f-value">'+ allFilters[i].val +'</span><span class="icon cross-icon remove-filter"></span></span></span>';
|
||||
$('.filter-row-two').append(filter_card);
|
||||
|
||||
}
|
||||
|
|
@ -290,64 +365,88 @@
|
|||
|
||||
//This is being used for validation of url params and making array of filters
|
||||
function formURL(column, condition, response, urlparams,clabel) {
|
||||
/*validate the conditions here and do the replacements and
|
||||
push here in the all filters array*/
|
||||
|
||||
/* validate the conditions here and do the replacements and
|
||||
push here in the all filters array */
|
||||
var obj1 = {};
|
||||
|
||||
if(column == "" || condition == "" || response == "") {
|
||||
alert("Please mention all the fields for column, condition and match params for proper functioning");
|
||||
|
||||
alert("Some of the required field is null, please check column, condition and value properly.");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(allFilters1.length>0) {
|
||||
if(allFilters.length>0) {
|
||||
//case for repeated filter
|
||||
|
||||
if(column != "sort" && column != "search") {
|
||||
|
||||
filter_repeated = 0;
|
||||
for(j=0;j<allFilters1.length;j++) {
|
||||
if(allFilters1[j].column==column && allFilters1[j].cond==condition && allFilters1[j].val==response)
|
||||
|
||||
for(j=0;j<allFilters.length;j++) {
|
||||
|
||||
if(allFilters[j].column == column && allFilters[j].cond == condition && allFilters[j].val == response)
|
||||
{
|
||||
filter_repeated = 1;
|
||||
return false;
|
||||
} else if(allFilters[j].column == column) {
|
||||
|
||||
filter_repeated = 1;
|
||||
allFilters[j].cond = condition;
|
||||
allFilters[j].val = response;
|
||||
makeURL(true);
|
||||
|
||||
}
|
||||
}
|
||||
if(filter_repeated == 0) {
|
||||
|
||||
obj1.column = column;
|
||||
obj1.cond = condition;
|
||||
obj1.val = response;
|
||||
obj1.label = clabel;
|
||||
allFilters1.push(obj1);
|
||||
allFilters.push(obj1);
|
||||
obj1 = {};
|
||||
makeURL();
|
||||
}
|
||||
}
|
||||
if(column == "sort") {
|
||||
sort_exists = 0;
|
||||
for(j=0;j<allFilters1.length;j++) {
|
||||
if(allFilters1[j].column == "sort") {
|
||||
|
||||
if(allFilters1[j].column==column && allFilters1[j].cond==condition && allFilters1[j].val==response){
|
||||
sort_exists = 0;
|
||||
|
||||
for(j=0;j<allFilters.length;j++) {
|
||||
|
||||
if(allFilters[j].column == "sort") {
|
||||
|
||||
if(allFilters[j].column==column && allFilters[j].cond==condition && allFilters[j].val==response) {
|
||||
|
||||
if(response=="asc") {
|
||||
allFilters1[j].column = column;
|
||||
allFilters1[j].cond = condition;
|
||||
allFilters1[j].val = "desc";
|
||||
allFilters1[j].label = clabel;
|
||||
|
||||
allFilters[j].column = column;
|
||||
allFilters[j].cond = condition;
|
||||
allFilters[j].val = "desc";
|
||||
allFilters[j].label = clabel;
|
||||
makeURL();
|
||||
|
||||
}
|
||||
else {
|
||||
allFilters1[j].column = column;
|
||||
allFilters1[j].cond = condition;
|
||||
allFilters1[j].val = "asc";
|
||||
allFilters1[j].label = clabel;
|
||||
|
||||
allFilters[j].column = column;
|
||||
allFilters[j].cond = condition;
|
||||
allFilters[j].val = "asc";
|
||||
allFilters[j].label = clabel;
|
||||
makeURL();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
allFilters1[j].column = column;
|
||||
allFilters1[j].cond = condition;
|
||||
allFilters1[j].val = response;
|
||||
allFilters1[j].label = clabel;
|
||||
|
||||
allFilters[j].column = column;
|
||||
allFilters[j].cond = condition;
|
||||
allFilters[j].val = response;
|
||||
allFilters[j].label = clabel;
|
||||
makeURL();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -355,39 +454,46 @@
|
|||
}
|
||||
}
|
||||
if(column == "search") {
|
||||
|
||||
search_found = 0;
|
||||
for(j=0;j<allFilters1.length;j++) {
|
||||
if(allFilters1[j].column == "search") {
|
||||
allFilters1[j].column = column;
|
||||
allFilters1[j].cond = condition;
|
||||
allFilters1[j].val = response;
|
||||
allFilters1[j].label = clabel;
|
||||
|
||||
for(j=0;j<allFilters.length;j++) {
|
||||
|
||||
if(allFilters[j].column == "search") {
|
||||
allFilters[j].column = column;
|
||||
allFilters[j].cond = condition;
|
||||
allFilters[j].val = response;
|
||||
allFilters[j].label = clabel;
|
||||
makeURL();
|
||||
}
|
||||
}
|
||||
for(j=0;j<allFilters1.length;j++) {
|
||||
if(allFilters1[j].column == "search") {
|
||||
|
||||
for(j=0;j<allFilters.length;j++) {
|
||||
if(allFilters[j].column == "search") {
|
||||
search_found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(search_found == 0) {
|
||||
obj1.column = column;
|
||||
obj1.cond = condition;
|
||||
obj1.val = response;
|
||||
obj1.label = clabel;
|
||||
allFilters1.push(obj1);
|
||||
allFilters.push(obj1);
|
||||
obj1 = {};
|
||||
makeURL();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
obj1.column = column;
|
||||
obj1.cond = condition;
|
||||
obj1.val = response;
|
||||
obj1.label = clabel;
|
||||
allFilters1.push(obj1);
|
||||
allFilters.push(obj1);
|
||||
obj1 = {};
|
||||
makeURL();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue