APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
492 stars 344 forks source link

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

Open GSpecDrum opened 6 years ago

GSpecDrum commented 6 years ago

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:

https://github.com/APY/APYDataGridBundle/blob/58f4e370ba79bd7d593a3759010ab002b3946b61/Grid/Grid.php#L927-L936

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: https://github.com/APY/APYDataGridBundle/blob/58f4e370ba79bd7d593a3759010ab002b3946b61/Grid/Grid.php#L791-L824