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

Can I Change the default label and placeholder generated in the inputs of the FilterControl class? #20

Open
pascualm4 opened this issue Jul 20, 2016 · 7 comments

Comments

@pascualm4
Copy link

I want to change the default labels of the inputs but when i change that the filters doesn't works well.

Any ideas to solve that?

Thanks in advance.

@Nayjest
Copy link
Member

Nayjest commented Jul 20, 2016

Hi!
It's strange becouse label properties are used only for displaying labels.
Please show code example.

@pascualm4
Copy link
Author

This following is my code:

`$provider = new ArrayDataProvider($actions->toArray());

        $input = new InputSource($_GET);
        $sortingInput = new InputOption('sort', $_GET);

        $grid = new Grid($provider, [
            new Column('id'),
            (new Column(trans('name')))
                ->setLabel(ucfirst(trans('labels.name')))
            ,
            (new Column('section'))
                ->setLabel(ucfirst(trans('labels.section')))
                ->setValueCalculator(function($row){
                    return $row->section['name'];
                })
            ,
            (new Column('actions'))
                ->setLabel(ucfirst(trans('labels.actions')))
                ->setValueCalculator(function($row){
                    return "<a href='".route('actions.show', [$row->id])."'><img src='/images/icon_ver_off.png' width='26'></a>
                        | <a href='".route('actions.edit', [$row->id])."'><img src='/images/icon_edit_off.png' width='26'></a>
                        | <a href='".route('actions.delete', [$row->id])."' onclick='return confirm('".trans('messages.delete')."')'><img src='/images/icon_eliminar_off.png' width='26'></a>
                        ";
                })
            ,
            new FilterControl('name', FilterOperation::OPERATOR_STR_CONTAINS, $input->option('name')),
            new FilterControl('section.name', FilterOperation::OPERATOR_STR_CONTAINS, $input->option('section')),
            new PaginationControl($input->option('page', 1), 10),
            new ColumnSortingControl('id', $sortingInput),
            new ColumnSortingControl('name', $sortingInput),
            new ColumnSortingControl('section', $sortingInput),
        ]);

        BootstrapStyling::applyTo($grid);`

I just want to change the default label and placeholder generated by the FilterControl in the end of the code.

@Nayjest
Copy link
Member

Nayjest commented Jul 20, 2016

  1. When creating control save it to variable for easy access
$nameFilter = new FilterControl('name', FilterOperation::OPERATOR_STR_CONTAINS, $input->option('name'))

You can use this expression directly when describing components array, just add $nameFilter = before filter instantiation in your code.
2. FilterControl by itself isn't responsible for how it looks, it has view component inside, if you look to https://github.com/view-components/view-components/blob/master/src/Component/Control/FilterControl.php you will see that there is simple template view with template named 'input'.

See this template: https://github.com/view-components/view-components/blob/master/resources/views/input.php

There is $label view variable.
FilterControl already adds there $label variable in setViewData() method, but it calls $view->setDefaultData($defaults) that should not overwrite already existing variables.

So, we need just set $label view variable somewhere before grid rendering.

$filterControl->getView()->setDataItem('label', 'My Label');

(See https://github.com/view-components/view-components/blob/master/src/Data/ArrayDataAggregateInterface.php)

@Nayjest
Copy link
Member

Nayjest commented Jul 20, 2016

Please give me know if it helps.

@vismutx
Copy link

vismutx commented Jul 31, 2017

I done so

(new Tag('td'))->addChild( (new FilterControl( 'ek', FilterOperation::OPERATOR_LIKE, new InputOption('ek', $_GET) ))->setView( new TemplateView('input', [ 'label' => null, 'placeholder' => 'ek' ]) ) ),

@muokid3
Copy link

muokid3 commented Sep 29, 2017

this worked for me!
all i had to do is create my filtercontrol like
$date = new FilterControl('date_created', FilterOperation::OPERATOR_LIKE, $input->option('date_created')),
then do
$date->getView()->setDataItem('label', 'Date'); just before $grid = $grid->render();

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

5 participants
@Nayjest @vismutx @pascualm4 @muokid3 and others