bugloos/grid-bundle

An easy to use grid view generator for symfony

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Type:symfony-bundle

v1.0.2 2020-09-21 04:54 UTC

This package is not auto-updated.

Last update: 2020-11-02 18:22:00 UTC


README

Installation

composer require bugloos/grid-bundle

Usage

Controller

$gridManager = $this->get('bugloos.grid_view.manager');

$adapter = (new ArrayAdapter())
            ->setSource($arrayOfData);

$gridManager = $gridManager
    ->setAdapter($adapter)
    ->setRequest($request)
    ->setDefaultOrder('c.id', SORT_ASC)
    ->setPageSize(25)
    ->setColumns([
        'c.id' => [
            'type' => IntegerColumn::class,
            'label' => 'ID',
            'widthPercent' => '5',
            'sortable' => true,
            'attribute' => 'id',
        ],
    ]); // List of columns to show in the grid

    return $this->render('grid.html.twig', [
        'grid' => $gridManager->getOutput(),
    ]);

View

{% embed '@BugloosGrid/grid/default.html.twig' with {'grid': grid} %}{% endembed %}

1. Column Types

EnumColumn

Bugloos\GridBundle\Column\EnumColumn

'status' => [
    'type' => EnumColumn::class,
    'label' => 'Status',
    'sortable' => true,
    'searchable' => true,

    'options' => [
        -1 => 'Banned',
        0 => 'Pending',
        1 => 'Active',
    ],
]

TextColumn

Bugloos\GridBundle\Column\TextColumn

'c.last_name' => [
    'type' => TextColumn::class,
    'label' => 'Last Name',
    'widthPercent' => '50',
    'searchable' => true,
    'attribute' => 'last_name', // Set attribute when using query adapter

    'maxLength' => 10,
]

IntegerColumn

Bugloos\GridBundle\Column\IntegerColumn

DecimalColumn

Bugloos\GridBundle\Column\DecimalColumn

'my_field' => [
    'type' => DecimalColumn::class,
    'label' => 'Decimal field',

    'decimals' => 5
],

DateColumn

Bugloos\GridBundle\Column\DateColumn

date' => [
    'type' => DateColumn::class,
    'label' => 'Created at',
    'sortable' => true,

    'dateFormat' => 'Y M d',
    'timeFormat' => 'H:m A', // Disable it by false value
]

2. Adapters

Query

public function getGridViewQuery()
{
    return $this->createQueryBuilder('c')
        ->andWhere('c.exampleField = :val')
        ->setParameter('val', $value)
    ;
}
$query = $repo->getGridViewQuery();

$adapter = (new QueryAdapter())
    ->setSource($query);

Array

$sample = [
    [
        'hashtag' => 'a7e87329b5eab8578f4f1098a152d6f4',
        'title' => 'Flower',
        'order' => 3,
        'my_val' => 10 / 3,
        'date' => strtotime('-1 Year'),
        'status' => 1,
        'test' => 5
        ]
];
$adapter = (new ArrayAdapter())
    ->setSource($sample);