2017 © Pedro Peláez
 

library twigrid

Experimental DataGrid for Nette Framework

image

uestla/twigrid

Experimental DataGrid for Nette Framework

  • Tuesday, May 29, 2018
  • by uestla
  • Repository
  • 5 Watchers
  • 12 Stars
  • 2,490 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 10 Forks
  • 9 Open issues
  • 61 Versions
  • 2 % Grown

The README.md

TwiGrid

... is a DataGrid for Nette Framework., (*1)

Buy me a Coffee, (*2)

Demo: https://kesspess.cz/twigrid/
Demo sources: https://github.com/uestla/twigrid-demo, (*3)

It's based on another (and great) datagrid written by @hrach - https://github.com/nextras/datagrid. My datagrid is hugely inspired by this component and its programming ideas and therefore I would like to give this man a maximum credit and respect :-), (*4)

Quickstart

Let's see how many steps do we have to make to create our first datagrid., (*5)

  1. Create new project

    composer create-project nette/web-project twigrid-quickstart
    
  2. Install TwiGrid & client-side assets

    cd twigrid-quickstart
    composer require uestla/twigrid
    yarn add twigrid-datagrid --modules-folder www/vendor
    

    If you're not using yarn, you can install assets manually by looking into package.json and see required dependencies there., (*6)

    We'll then update app/Presenters/templates/@layout.latte to load downloaded assets:, (*7)

    
    
    <link rel="stylesheet" href="{$basePath}/vendor/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="{$basePath}/vendor/twigrid-datagrid/assets/twigrid.datagrid.css">
    
    
    
    
    
    
    
  3. Database

    Download the SQLite3 file from the demo application and place it in app/Model/users.s3db., (*8)

    And we'll configure this database to be used by the application:, (*9)

    # config/local.neon
    database:
        dsn: 'sqlite:%appDir%/Model/users.s3db'
    
  4. Create datagrid

    Now it's finally time to create our first datagrid - let's create an app/Grids/UsersGrid.php file. We'll need database connection for data loading, so we inject it properly via constructor., (*10)

    // app/Grids/UsersGrid.php
    
    final class UsersGrid extends TwiGrid\DataGrid
    {
        private $database;
    
        public function __construct(Nette\Database\Explorer $database)
        {
            parent::__construct();
    
            $this->database = $database;
        }
    
        protected function build(): void
        {
            // TODO
        }
    }
    

    We'll define the datagrid body inside the build() method. Although the table user has many columns, we'll have just some of them in our grid just to make it easy., (*11)

    // app/Grids/UsersGrid.php
    
    final class UsersGrid extends TwiGrid\DataGrid
    {
        // ...
    
        protected function build(): void
        {
            $this->addColumn('firstname', 'Firstname');
            $this->addColumn('surname', 'Surname');
            $this->addColumn('streetaddress', 'Street address');
            $this->addColumn('city', 'City');
            $this->addColumn('country_code', 'Country');
        }
    }
    

    TwiGrid also needs to know what column(s) it should consider as a primary key:, (*12)

    $this->setPrimaryKey('id');
    

    And finally we'll tell TwiGrid how to load our users:, (*13)

    $this->setDataLoader(function () {
        return $this->database->table('user');
    });
    
  5. To properly inject our grid into presenters, we'll need to create a factory interface:, (*14)

    // app/Grids/UsersGridFactory.php
    
    interface UsersGridFactory
    {
        public function create(): UsersGrid;
    }
    

    This interface will now be used for automatic factory generation, which is handy - we simply add this definition to config/common.neon:, (*15)

    services:
        - implement: UsersGridFactory
    
  6. Having all of this done, we can now simply inject our grid factory into HomepagePresenter., (*16)

    // app/Presenters/HomepagePresenter.php
    
    class HomepagePresenter extends BasePresenter
    {
        /** @var \UsersGridFactory @inject */
        public $usersGridFactory;
    }
    

    Now we'll add the control factory itself:, (*17)

    // app/Presenters/HomepagePresenter.php
    
    protected function createComponentUsersGrid(): \UsersGrid
    {
        return $this->usersGridFactory->create();
    }
    
  7. We're nearly done! Just open app/Presenters/templates/Homepage/default.latte, delete the whole content and replace it with, (*18)

    {block content}
        {control usersGrid}
    {/block}
    

    That's all, folks!, (*19)

    Now when you'll open the page, you might see something like this:, (*20)

    Result screenshot, (*21)

  8. Final improvement, (*22)

    Maybe showing the country code isn't that sexy - we'd like to have the whole country name in "Country" column. To achieve that, we'll create custom grid template:, (*23)

    {* app/Grids/UsersGrid.latte *}
    
    {extends $defaultTemplate}
    
    {define body-cell-country_code}
        <td>{$record->country->title}</td>
    {/define}
    

    And tell TwiGrid to use this template:, (*24)

    // app/Grids/UsersGrid.php::build()
    
    $this->setTemplateFile(__DIR__ . '/UsersGrid.latte');
    

    Simple as that!, (*25)

More

To see more examples, please visit the demo page. Enjoy!, (*26)

The Versions

29/05 2018
07/04 2017

11.2.3

11.2.3.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

nette datagrid addon

07/04 2017

11.2.2

11.2.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

nette datagrid addon

19/03 2017

11.2.1

11.2.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

nette datagrid addon

19/03 2017

11.2.0

11.2.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

nette datagrid addon

19/03 2017

11.1.0

11.1.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

The Development Requires

nette datagrid addon

18/03 2017

11.0.2

11.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

05/03 2017

11.0.1

11.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

03/03 2017

11.0.0

11.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

17/07 2016

dev-next-level

dev-next-level http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

08/07 2016

10.0.2

10.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

08/07 2016

10.0.1

10.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

08/07 2016

10.0.0

10.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

07/07 2016

9.0.1

9.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

07/07 2016

9.0.0

9.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/07 2016

8.0.2

8.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/07 2016

8.0.1

8.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/07 2016

8.0.0

8.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/07 2016

7.0.2

7.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

25/06 2016

7.0.1

7.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

25/06 2016

7.0.0

7.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

05/03 2016

6.0.8

6.0.8.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

17/11 2015

6.0.7

6.0.7.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

07/11 2015

6.0.6

6.0.6.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

08/09 2015

6.0.5

6.0.5.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

10/08 2015

6.0.4

6.0.4.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

31/05 2015
18/05 2015
24/04 2015
01/03 2015
23/01 2015
21/08 2014
13/08 2014
08/08 2014
03/08 2014
03/08 2014
02/08 2014
30/07 2014
14/07 2014
11/07 2014
05/07 2014
05/07 2014

3.0.1

3.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

13/05 2014

3.0.0

3.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

24/01 2014

2.0.3

2.0.3.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

11/01 2014

2.0.2

2.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

07/01 2014

2.0.1

2.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/01 2014

2.0.0

2.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

12/08 2013

1.0.3

1.0.3.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

10/08 2013

1.0.2

1.0.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

07/08 2013

1.0.1

1.0.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

13/06 2013

1.0.0

1.0.0.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

08/06 2013

0.9.5

0.9.5.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

06/06 2013

0.9.4

0.9.4.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

22/04 2013

0.9.3

0.9.3.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

19/04 2013

0.9.2

0.9.2.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon

15/04 2013

0.9.1

0.9.1.0 http://github.com/uestla/twigrid

Experimental DataGrid for Nette Framework

  Sources   Download

MIT

The Requires

 

nette datagrid addon