Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak filter with FilterType === 'select' #1017

Open
GSpecDrum opened this issue Jul 13, 2018 · 0 comments
Open

Tweak filter with FilterType === 'select' #1017

GSpecDrum opened this issue Jul 13, 2018 · 0 comments

Comments

@GSpecDrum
Copy link

GSpecDrum commented Jul 13, 2018

When you set filterType to 'select' on some column, you have this values stored in session:

  "column_name" => [
    "operator" => "btw"
    "from" => [
      0 => "value_1"
    ]
    "to" => "value_2"
  ]

this follows from form inputs:

<span class="grid-filter-select-query">
         <select name="grid_hash[column_name][from][]">
            <option value="">&nbsp;</option>
            <option value="0">value_1</option>
            <option value="1">value_2</option>
        </select>
        <select name="grid_hash[column_name][to]">
            <option value="">&nbsp;</option>
            <option value="0">value_1</option>
            <option value="1">value_2</option>
         </select>
</span>

It's strange, but working, OK

But when setting filters from tweaks, method processFilters called, where key 'to' perform to be array with zero element which value is value of 'to' element in income array:

// Convert simple value with select filter
if ($column->getFilterType() === 'select') {
if (isset($value['from']) && !is_array($value['from'])) {
$value['from'] = array($value['from']);
}
if (isset($value['to']) && !is_array($value['to'])) {
$value['to'] = array($value['to']);
}
}

This makes not woking properly select filters with range, which setted by tweak.

When setting from request, filters settings has saving as is, do not perform as in code above:

protected function processRequestFilters()
{
$filtering = false;
foreach ($this->columns as $column) {
if ($column->isFilterable()) {
$ColumnId = $column->getId();
// Get data from request
$data = $this->getFromRequest($ColumnId);
//if no item is selectd in multi select filter : simulate empty first choice
if( $column->getFilterType() == 'select'
&& $column->getSelectMulti() == true
&& $data == null
&& $this->getFromRequest(self::REQUEST_QUERY_PAGE) == null
&& $this->getFromRequest(self::REQUEST_QUERY_ORDER) == null
&& $this->getFromRequest(self::REQUEST_QUERY_LIMIT) == null
&& ($this->getFromRequest(self::REQUEST_QUERY_MASS_ACTION) == null || $this->getFromRequest(self::REQUEST_QUERY_MASS_ACTION) == "-1")){
$data = array('from'=>'');
}
// Store in the session
$this->set($ColumnId, $data);
// Filtering ?
if (!$filtering && $data !== null) {
$filtering = true;
}
}
}
return $filtering;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant