dudapiotr / ZfTable

*Not supported*ZfTable 3.1. Awesome ZF2 table / grid (and much much more) generator with huge possibilities of decorating and conditioning. Integrated with DataTables, Doctrine 2, Bootstrap 2.0 and 3.0.
http://dudapiotrek.laohost.net/
MIT License
75 stars 59 forks source link

Column filtering with a date picker #5

Closed isurugit closed 10 years ago

isurugit commented 10 years ago

Hi,

First of all, thank you very much for your nice module. Let us know, how to add a date picker to table column filters.

For example : If table has a column like "Birthday", then how do we add a date picker to search filter of this birthday column ?

Thanks.

dudapiotr commented 10 years ago

Hi, At first, It's really good idea to add this feature to module. So I think in next realese, filters will be more flexible.

Reffering to issue:

You have to change method renderFilters in Render.php. Now, if params is string it's create Text, in other way we create Select element.

If we want date picker, generally we have to add additional class.

public function renderFilters()
{
    $headers = $this->getTable()->getHeaders();
    $render = '';

    foreach ($headers as $name => $params) {
        if (isset($params['filters'])) {
            $value = $this->getTable()->getParamAdapter()->getValueOfFilter($name);
            $id = 'zff_'.$name;
            if (is_string($params['filters'])) {
                $element = new \Zend\Form\Element\Text($id);
            } else {
                $element = new \Zend\Form\Element\Select($id);
                $element->setValueOptions($params['filters']);
            }
            $element->setAttribute('class', 'filter form-control');
            $element->setValue($value);

            $render .= sprintf('<td>%s</td>', $this->getRenderer()->formRow($element));
        } else {
            $render .= '<td></td>';
        }
    }
    return sprintf('<tr>%s</tr>', $render);
}
isurugit commented 10 years ago

Thank you very much for your quick response, I added this $element = new \Zend\Form\Element\Date($id); with a relevant logic. It is working perfectly. :+1:

dudapiotr commented 10 years ago

Great!