Forums

default value of dynamic filtering

admin_wiky 22 Sep, 2015
Hi all
I am using dynamic filtering on my page, filtered by season (named: obdobi) .... this variable is in form: YYYY-MM (like 2015-09).
condition is set to all season (named: celé období) on first load page (all data are loaded) and I need set condition to latest season (now 2015-09) but not by sql query.
here is code of dynamic dropdown menu:

  // button for filtering by date season
  $keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
  $values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
  array_unshift($keys, '');
  array_unshift($values, 'celé období');
  $options = array_combine($keys, $values);
  $field = array 
  (
    'name' => 'fltr[pk][obdobi]',
    'id' => '',
    'options' => 
    array (
    ),
    'empty' => '',
    'values' => 
    array (
    ),
    'label' => 
    array (
      'text' => '',
      'position' => '',
    ),
    'sublabel' => '',
    'multiple' => '0',
    'size' => '',
    'class' => '',
    'title' => '',
    'style' => 'float:left;',
    'params' => '',
    ':data-load-state' => '',
    ':data-tooltip' => '',
    'type' => 'dropdown',
    'container_id' => '1',
  );
  $field["options"] = $options;
  echo '<div style="float:right;position:relative;">'.\GCore\Helpers\Html::formLine($field["name"], $field).'</div>';


But I dont know how to modify this code to get filter to latest value (now 2015-09).
someone knows?

thank you
GreyHead 22 Sep, 2015
Hi homeopat,

I'm not sure I fully understand but this might help ???
// button for filtering by date season
$keys = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
$values = \GCore\Libs\Arr::getVal(\GCore\Libs\Arr::getVal($rows, explode(".", "[n].pk")), explode(".", "[n].obdobi"));
array_unshift($keys, '');
array_unshift($values, 'celé období');
$options = array_combine($keys, $values);
$field = array 
(
  'name' => 'fltr[pk][obdobi]',
  'id' => '',
  'options' => $options, // changed
  'empty' => '',
  'values' => array (date('Y-m')), // changed
  'label' => array (
    'text' => '',
    'position' => '',
  ),
  'sublabel' => '',
  'multiple' => '0',
  'size' => '',
  'class' => '',
  'title' => '',
  'style' => 'float:left;',
  'params' => '',
  ':data-load-state' => '',
  ':data-tooltip' => '',
  'type' => 'dropdown',
  'container_id' => '1',
);
//  $field["options"] = $options; //removed
echo '<div style="float:right;position:relative;">'.\GCore\Helpers\Html::formLine($field["name"], $field).'</div>';

Bob
admin_wiky 22 Sep, 2015
Hi bob,

thank you.
It set the value in dropdown, but not apply the filter. I must click on apply button and that is half of what I wanted, if u understand me.
GreyHead 22 Sep, 2015
Hi homeopat,

Then you also need to add it in the Conditions box. You can do this by checking if another value is already set, and if not, use the date() one.

Bob
admin_wiky 22 Sep, 2015
Hi Bob,

do you mean in condition box in model? but what variable I have to watch?
do you mean put all code above (in this article) to conditions box?
GreyHead 23 Sep, 2015
Hi homeopat,

I assume that your code is in the Header box to build a filter? So it should stay there.

In the Conditions box you just want to set the default filter? Is that right?

Bob
admin_wiky 23 Sep, 2015
Hi Bob,
Yes, My code is in the header box.
Yes, I want to set default filter. But dont know what variable affect default filter value.

thx
This topic is locked and no more replies can be posted.