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

Better documentation #22

Open
davidkudera opened this issue Nov 9, 2015 · 2 comments
Open

Better documentation #22

davidkudera opened this issue Nov 9, 2015 · 2 comments

Comments

@davidkudera
Copy link
Member

  • Explain data sources
@wodCZ
Copy link

wodCZ commented Dec 2, 2015

I would use example/explanation of form rendering as I can't manage it to work. Concretely how to access filteringForm from template.

Would you please provide simple example of table with filtering?

If you do not have time for documentation, you can put simple example here and I will prepare PR.

Thanks!

@davidkudera
Copy link
Member Author

hello, here is one example:

/**
 *
 * @author David Kudera <[email protected]>
 */
class BrowseList extends Control
{


    /**
     * @return \Carrooi\NoGrid\NoGrid
     */
    protected function createComponentGrid()
    {
        $grid = $this->gridFactory->create(new DoctrineQueryFunctionDataSource(...));
        $grid->setFilteringForm($this->createFilteringForm(), 'reset');

        $grid->addFilter('name', Condition::LIKE, [
            Condition::CASE_INSENSITIVE => true,
        ]/*, function($name) {       // customize DQL parameter
            return '%'. $name. '%';
        }*/);

        return $grid;
    }


    /**
     * @return \Nette\Application\UI\Form
     */
    private function createFilteringForm()
    {
        $form = new Form;

        $form->addText('name');

        $form->addSubmit('search', 'Search');
        $form->addSubmit('reset', 'Reset');

        return $form;
    }

}

and template:

<table n:no-grid="grid">
    <thead>
        <tr>
            <th>Name</th>
            <th>Actions</th>
        </tr>
        <tr>
            <td>
                <input n:name="name">
            </td>
            <td>
                <input n:name="search">
                <input n:name="reset">
            </td>
        </tr>
    </thead>
    <tbody>
        <tr n:no-grid-data-as="$user">
            <td>
                {$user->getName()}
            </td>
            <td>
                <a href="#">Edit</a>
                <a href="#">Remove</a>
            </td>
        </tr>
    </tbody>
</table>

<form> element is automatically created by noGrid itself.

Btw if you would have some free time for creating PR, I would be really glad and happy 🍻

Write in case of any problem.

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

2 participants