PHP code example of phloxcz / components-grid

1. Go to this page and download the library: Download phloxcz/components-grid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phloxcz / components-grid example snippets


use Phlox\Components\Grid\GridControl;

class UserPresenter extends Nette\Application\UI\Presenter
{
    public function __construct(
        private readonly Nette\Database\Explorer $db,
    ) {}

    protected function createComponentUserGrid(): GridControl
    {
        $grid = new GridControl();

        $grid->setDataSource($this->db->table('user'))
             ->setItemsPerPage(25)
             ->setTheme(GridControl::BOOTSTRAP)
             ->useAjax()
             ->setResizable()
             ->setReorderable()
             ->showColumnToggle();

        $grid->addTextColumn('name', 'Jméno')
             ->sortable()
             ->searchable()
             ->filterable();

        $grid->addTextColumn('email', 'E-mail')
             ->sortable()
             ->width('220px');

        $grid->addDateColumn('created_at', 'Registrace', 'd.m.Y')
             ->sortable();

        $grid->addBoolColumn('active', 'Aktivní');

        $grid->addActionColumn('actions', '')
             ->addPrimaryAction('', fn($row) => $this->link('edit', $row['id']), 'bi bi-pencil', title: 'Upravit')
             ->addAction('Smazat', fn($row) => $this->link('delete!', $row['id']), 'bi bi-trash', 'text-danger', 'Opravdu smazat?');

        // Hromadné akce
        $grid->setPrimaryKey('id')
             ->addBulkAction('delete', 'Smazat', fn($ids) => $this->handleBulkDelete($ids),
                 icon: 'bi bi-trash', confirm: 'Opravdu smazat?');

        return $grid;
    }
}