2017 © Pedro Peláez
 

symfony-bundle table

Symfony Ajax Datagrid Bundle for doctrine entities

image

kilik/table

Symfony Ajax Datagrid Bundle for doctrine entities

  • Friday, June 1, 2018
  • by mitch10593
  • Repository
  • 4 Watchers
  • 7 Stars
  • 3,588 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 36 Versions
  • 35 % Grown

The README.md

README

What's KilikTableBundle ?

KilikTableBundle is a fast, modern, and easy-to-use way to manipulate paginated information, with filtering and ordering features, with ajax queries., (*1)

This bundle is a work in progress., (*2)

Links:

Working features:

  • pagination
  • basic filtering (like %...%)
  • advanced filtering (,,=,=,=,!,!=)
  • ordering by column (and reverse)
  • basic table template extendable
  • keep filters and orders in browser local storage (api REST)
  • filtering on queries with group by
  • show ordered column (normal and reverse)
  • max items per page selector (customizable)
  • delay on keyup events (to prevent multiple reloads)
  • checkbox and select filter
  • CSV export of filtered rows
  • customization of visible columns (hide/show checkboxes)
  • column display colum cells with callback
  • custom display colum cells with template
  • multiple lists on one page
  • pre-load default filters and reset local storage filters
  • smart filtering on many words (Filter::TYPE_LIKE_WORDS_AND)
  • (beta) support api calls to load resources via web services

Planned features:

  • more translations
  • add advanced templates

Installation

composer require kilik/table

Patch your AppKernel.php (symfony <4):, (*3)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new \Kilik\TableBundle\KilikTableBundle(),
        ];

        // ...
    }
}    

Patch your AppKernel.php (symfony >=4):, (*4)

<?php

return [
    Kilik\TableBundle\KilikTableBundle::class => ['all' => true],
];

Install assets, (*5)

./bin/console assets:install --symlink

And create your first list:, (*6)

Feature disabled on 1.0 branch (symfony 4 compatibility WIP), (*7)

./bin/console kilik:table:generate

(With default parameters, your list is available here http://localhost/yourcontroller/list), (*8)

Usage

This documentation need to be completed., (*9)

Here, some examples to show latest features., (*10)

Optimized version to load entities, from Repository Name:, (*11)

$table = (new Table())
    // ...
    ->setEntityLoaderRepository("KilikDemoBundle:Product")
    // ...

Optimized version to load entities, from Callback method (Eager loading):, (*12)

$table = (new Table())
    // ...
    ->setEntityLoaderCallback(function($ids) {
        return $this->manager()->getRepository('KilikDemoBundle:Product')->findById($ids);
    })
// ...

Mass actions

Define a mass action for list, (*13)


$massAction = new MassAction('delete', 'Delete selected items'); // First parameter 'delete' must not contain space or special characters (identifier) $massAction->setAction('path/to/my-form-action.php'); $table = (new Table()) // ... ->addMassAction($massAction) // ... // Then your form action, you can grab selected rows as entities $selectedEntities = $this->get('kilik_table') ->getSelectedRows($request, $this->getTable()); foreach ($selectedEntities as $entity) { // ... $entity->doSomething(); // ... }

If mass action does not have a specified action, a javascript event is fired. You can get all rows checked as following :, (*14)

 $("#table_id").on('kilik:massAction', function (e, detail) {
    if (detail.checked.length === 0) return false;
    if (detail.action === 'delete') {
        //...
    }
});

Events / Listeners

  • kilik:init:start jQuery event when table init process starts
$(document).on('kilik:init:start', function(event, table) {
    // Do something with event or table object
});
  • kilik:init:end jQuery event when table init process ends
$(document).on('kilik:init:start', function(event, table) {
    // Do something with event or table object
});

Autoload Kilik Tables

A new twig block provide metadata information about table so you can autoload it if necessary without any javascript in your twig template., (*15)

{% block tableMetadata %}
    <div style="display:none;width:0; height:0;" data-kiliktable-id="{{ table.id }}" data-kiliktable-path="{{ table.path }}">{{ table.options | json_encode | raw }}</div>
{% endblock tableMetadata %}

You can access table configurations from HTML attributes with jQuery, see the example :, (*16)

var loadKiliktables = function() {
    var $kilikTables = $("[data-kiliktable-id]");
    if ($kilikTables && $kilikTables.length > 0) {
        $kilikTables.each(function(index, currentTable){
            var $currentTable = $(currentTable);
            var id = $currentTable.data("kiliktable-id");
            if (id.length > 0) {
                var path = $currentTable.data("kiliktable-path");
                var options = $currentTable.html();
                new KilikTableFA(id, path, JSON.parse(options)).init();
            }
        });
    }
}

Bootstrap 4

Note: WIP on Bootstrap 4 (with Font Awesome) integration, use new JS function:, (*17)

$(document).ready(function () {
    var table = new KilikTableFA("{{ table.id }}", "{{ table.path }}", JSON.parse('{{ table.options | json_encode |raw }}'));
    table.init();
});

Use other storage for table filters

If you want to use a custom storage for table filters (Eg. Session)., (*18)

// Disable using javascript local storage form filters
public function getTable()
{
    return (new Table())->setSkipLoadFilterFromLocalStorage(true);
}

// On ajax action : store filters data
public function _list(Request $request)
{
    $table = $this->getTable();
    $response = $this->get('kilik_table')->handleRequest($table, $request);

    // Handle request for table form
    $this->kilik->createFormView($table);
    $table->getForm()->handleRequest($request);
    $data = $table->getForm()->getData();

    $this->filterStorage->store($data); // Use your custom storage

    return $response;
}


// On default action
public function list()
{
    $table = $this->getTable();
    $data = $this->filterStorage->get();

    return $this->render('list.html.twig', array(
        'table' => $this->kilik->createFormView($table, $data),
    ));
}

Customize filled filters

When a filter is filled, class table-filter-filled is added on field. By default, no style is applied, but you can override it to fit your needs :, (*19)

.table-filter-filled {
    ...
}

Filter date columns

$table
    ->addColumn(
        (new Column())
            ->setSort(['u.createdAt' => 'asc'])
            ->setDisplayFormat(Column::FORMAT_DATE)
            ->setDisplayFormatParams('d/m/Y H:i:s') // or for example FilterDate::INPUT_FORMAT_LITTLE_ENDIAN
            ->setFilter((new FilterDate())
                ->setName('u_createdAt')
                ->setField('u.createdAt')
                ->setInputFormat(FilterDate::INPUT_FORMAT_LITTLE_ENDIAN)
            )
    )
;

Users can filter this data using various operators, for example : - 26/02/1802 or =26/02/1802 : expects a specific day - !=21/11/1694 : expects any day except 21 November 1694 - >26/02/1802 18:00 : expects specific day after 18:00 and without end limit - >=02/1802 : expects in february 1802 and after - <2024 : expects in 2023 and before - <=26/02/1802 15 : expects 26 February 1802 at 3pm or earlier - = : expects date is NULL - != : expects date is not NULL, (*20)

For bundle developpers

# prepare tests
./prepare-tests.sh

# run tests
./run-tests.sh

# launch composer
./scripts/composer.sh

The Versions

01/06 2018

dev-master

9999999-dev https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table symfony

01/06 2018

dev-fix/abort-current-ajax-query-requesting-a-new-one

dev-fix/abort-current-ajax-query-requesting-a-new-one https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

14/05 2018

1.0.1

1.0.1.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

14/05 2018

dev-25-fix-warning-on-missing-translations

dev-25-fix-warning-on-missing-translations https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

14/05 2018

dev-fix-symfony-3.4-compatibility

dev-fix-symfony-3.4-compatibility https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

25/04 2018

1.0.0

1.0.0.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

25/04 2018

dev-22-fix-symfony-4-compatibility

dev-22-fix-symfony-4-compatibility https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

25/04 2018

dev-symfony-3

dev-symfony-3 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

05/04 2018

dev-symfony-3.3

dev-symfony-3.3 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

05/04 2018

0.2.8

0.2.8.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

05/04 2018

dev-19-error-table-generator

dev-19-error-table-generator https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

05/04 2018

0.2.7

0.2.7.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

15/02 2018

0.2.6

0.2.6.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

15/02 2018

dev-feature/define-mass-actions

dev-feature/define-mass-actions https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

02/02 2018

0.2.5

0.2.5.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

02/02 2018

dev-feature/handle-column-header-class

dev-feature/handle-column-header-class https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

12/01 2018

0.2.4

0.2.4.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

12/01 2018

dev-add-table-generator

dev-add-table-generator https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

19/12 2017

0.2.3

0.2.3.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

19/12 2017

dev-no-table

dev-no-table https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

20/10 2017

dev-load-rows-with-api

dev-load-rows-with-api https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

03/07 2017

0.2.2

0.2.2.0 https://github.com/KilikFr/TableBundle

Symfony Ajax Datagrid Bundle for doctrine entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery table symfony

03/05 2017

0.2.1

0.2.1.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

16/11 2016

0.2.0

0.2.0.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

14/11 2016

0.1.9

0.1.9.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

22/08 2016

0.1.8

0.1.8.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

22/08 2016

dev-develop

dev-develop https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

10/08 2016

dev-add-identifier-field-names

dev-add-identifier-field-names https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

05/08 2016

0.1.7

0.1.7.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

17/06 2016

0.1.6

0.1.6.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

16/06 2016

0.1.5

0.1.5.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

10/06 2016

0.1.4

0.1.4.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

20/05 2016

0.1.3

0.1.3.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

04/04 2016

0.1.2

0.1.2.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

03/03 2016

0.1.1

0.1.1.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table

01/03 2016

0.1.0

0.1.0.0 https://github.com/KilikFr/TableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities

  Sources   Download

MIT

The Requires

 

by Michel Naud

jquery symfony2 table