PHPackages                             pawellen/listing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pawellen/listing

ActiveSymfony-bundle

pawellen/listing
================

Listing Bundle providing easy datatables (http://www.datatables.net/) usage in symfony projects

v0.8.0(1y ago)210.9k↓44.9%1MITJavaScriptPHP &gt;=8.0

Since Mar 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/pawellen/listing)[ Packagist](https://packagist.org/packages/pawellen/listing)[ Docs](https://github.com/pawellen/listing)[ RSS](/packages/pawellen-listing/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (46)Used By (0)

listing
=======

[](#listing)

Builder style data table backend plugin for datatables.net js plugin

Version 2 with Symfony 4.4 support

Based on:

DataTables Listing plugin
=========================

[](#datatables-listing-plugin)

[![Codacy Badge](https://camo.githubusercontent.com/cbc973ac9575bdf30eb2000b40a3b83e589aecd183c09d8d16c2944f0b7780e5/68747470733a2f2f7777772e636f646163792e636f6d2f70726f6a6563742f62616467652f3662346432313435636362323466353261393039323930643333383033616564)](https://www.codacy.com/public/pawellen/DataTablesListing)[![Build Status](https://camo.githubusercontent.com/259600c3526fa4b45591476f5c70f678a3f215f957b7b95d7c45e70d8583e5c8/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f706177656c6c656e2f446174615461626c65734c697374696e672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/pawellen/DataTablesListing)

Data tables listing plugin allow you to easy creating record list, using Symfony forms style. This plugin use popular JQuery DataTables plug ()

Installation
============

[](#installation)

1. Install plugin using composer:

```
{
    "pawellen/data-tables-listing": "dev-master"
}
```

2. Update Your AppKernel.php

```
    $bundles = array (
        (...)
        new PawelLen\DataTablesListing\DataTablesListingBundle()
    );

2,5. Configuration:

data_tables_listing:
    default_template: LenPanelBundle::listing_div_layout.html.twig
    include_assets:
        datatables_js: false
        datatables_css: false
        include_jquery: false
        jquery_js: "//code.jquery.com/jquery-2.1.3.min.js"

3. Add DataTables javascript script to your template using listing_scripts twig function.
Example:
```html

            (...)

            {{ listing_scripts() }}
            (...)

        (...)

```

4. Your listing is ready to use :)

Usage
=====

[](#usage)

1. Creating new table in controller.

---

To create listing you just need to get ***listing*** service in your controller and pass to it your listing type object. Example:

```
    /**
     * @Route("/user/list")
     * @Template()
     */
    public function listAction(Request $request)
    {
        // Creates new listing object:
        $list = $this->get('listing')->createListing(new UserListing(), array(
            'request' => $request
        ));

        // Handle ajax request that provide data to listing:
        if ($request->isXmlHttpRequest()) {

            return $list->createResponse($request);
        }

        // Pass ListView object to your template:
        return array(
            'list' => $list->createView()
        );
    }
```

As you can see usage of listing is very similar to Symfony forms component. As one of options passed to ***createListing*** method is Request object. Request object is used to get any data passed form your site, for example filters, column order by itp...

2. Creating own ListingType

---

Creating new listing type looks similar like creation of symfony form. Example:

```
namespace Td\UserBundle\Listing;

use PawelLen\DataTablesListing\Type\AbstractType;
use PawelLen\DataTablesListing\Filters\FilterBuilderInterface;
use PawelLen\DataTablesListing\Listing\ListingBuilderInterface;

class UserListing extends AbstractType
{
    public function buildFilters(FilterBuilderInterface $builder, array $options)
    {
        $builder->add('name', 'text', array(
            'label' => 'User name',
            'required' => false,
            'filter' => array(
                'property' => 'name',
                'expression' => 'c.name LIKE :name'
            )
        ));
        $builder->add('email', 'text', array(
            'label' => 'Email',
            'required' => false,
            'filter' => array(
                'expression' => 'c.shortName LIKE :shortName'
            )
        ));
    }

    public function buildListing(ListingBuilderInterface $builder, array $options)
    {
        $builder->add('id', 'column', array(
            'label' => 'Id'
        ));
        $builder->add('name', 'column', array(
            'label' => 'User name'
        ));
        $builder->add('email', 'column', array(
            'label' => 'Email'
        ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'class' => 'TdUserBundle:User'
        ));
    }

    public function getName()
    {
        return 'my_list';
    }
}
```

This will create listing of users with two filter fields and three columns. ***Data source is pointed in setDefaultOptions*** method. Instead of single entity passed in "class" option you can use also option query\_builder and provide query builder interface to access more complicated query with joins.

3. Template

---

To render created listing, you must pass ListingView object to your template: Example:

```
{% extends "PanelBundle::base_template.html.twig" %}

{% form_theme list.filters _self %}

{% block _my_list_widget %}

            {{ form_row(form.name) }}

            {{ form_row(form.email) }}

{% endblock _my_list_widget %}

{% block content_body %}
    {{ listing(list) }}
{% endblock %}
```

To render entire listing, you can use ***listing()*** twig function. This example shows also how to overwrite filters template. Notice that there is a leading underscore in block name.

Functions
=========

[](#functions)

1. Creating links

---

To create link you need to add ***link*** option inside ***buildListing*** method.

```
    $builder->add('name', 'column', array(
        'label' => 'User name',
        'link' => array(
            'route' => 'user_edit',
            'params' => array(
                'user_id' => 'id'
            )
        )
    ));
```

where: ***id*** is a ***propertyPath*** string. ***route*** is a route name ***params*** are parameters to generateUrl function

2. Using QueryBuilder

---

To use query builder you need to use ***query\_builder*** option instead of class.

```
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'query_builder' => function(QueryBuilder $builder) {
                $builder->select('u, a, t')
                  ->from('TdUserBundle:Contractor', 'u')
                  ->leftJoin('u.address', 'a')
                  ->leftJoin('u.type', 't')
                  ->where('u.deletedAt IS NULL');
            }
        ));
    }
```

or

```
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'class' => 'TdUserBundle:User',
            'query_builder' => function(EntityRepository $er) {
                return $er->createQueryBuilder('u')
                          ->where('u.deletedAt IS NULL');
            }
        ));
    }
```

3. Using filters

---

By default, when building filters form you don't need to define any filters, you may pass empty array as filter options, in this case default search will be performed. Default search use "name LIKE %PHRASE%" sql query, where ***name*** is filter name and ***PHRASE***is the value of input. To use custom filter just pass the DQL expression to filter option. Example:

```
    $builder->add('name', 'text', array(
        'label' => 'User name',
        'required' => false,
        'filter' => array(
            'expression' => 'u.name LIKE :name',
            'eval' => '%like%'
        )
    ))
```

where: ***expression*** is a DQL expression, You can use parameter multiple times, for example: "u.firstname LIKE :name OR u.lastname LIKE :name". ***eval*** is not required parameter it is used to modify value passed from filter form

notice: ***:name*** MUST be always same as filter name (in current version)

4. Using query modifications when filter is used

---

In some cases your listing is very simple but there is case when you use some filters you have to add some complicated joins, but in other cases you don't want apply that joins to query because they are very expensive. Example:

```
    $builder->add('languageCode', 'text', array(
        'label' => 'Language code',
        'required' => false,
        'filter' => array(
            'expression' => 'l.code LIKE :languageCode',
            'eval' => '%like%',
            'query_builder' => function(QueryBuilder $builder) {
               $builder->addSelect('l')
                       ->join('c.language', 'l');
            }
        )
    ))
```

In this example when user fill "Language code" filter, ***join('c.language')*** will be added and languageCode condition will be added to query.

***Deprecated*** parameter joins (used in old version):

```
     // DEPRECATED:
     $builder->add('country', 'text', array(
         'label' => 'Country name',
         'required' => false,
         'filter' => array(
             'expression' => 'c.name LIKE :country',
             'eval' => '%like%',
             'join' => array(
                 array('field' => 'u.address', 'alias' => 'a'),
                 array('field' => 'a.country', 'alias' => 'c'),
             )
         )
     ))
```

In this case country will be joined only if country filter is passed by user, otherwise joins are not used.

5. Buttons

---

Inside ***buildListing*** method you can add action buttons to your list position. Example:

```
    ->add('edit', 'button', array(
        'label' => 'Edit',
        'route' => 'user_edit',
        'params' => array(
            'contractor_id' => 'id'
        )
    ))
```

6. Events

---

When you need dynamically modify/extend table rows or filters search criteria you can use one of listing events.

7. Accessing custom properties via PropertyAccessor

---

When using ***query\_bulder*** you can use option ***property*** to access any data from fetched entity. For example: If you have related entity you can can access its getter threw property accessor:

```
    $builder->add('status', 'text', array(
        'label' => 'Status',
        'property' => 'status.name',
    ));
```

or you can even can access first object in collection:

```
    $builder->add('user', 'text', array(
        'label' => 'First user',
        'property' => 'users[0].name',
    ));
```

listing allow you tu use some magic wildcard ***\[*\]**\*, to collect all values in collection and display it as coma separated string:

```
    $builder->add('user', 'text', array(
        'label' => 'Users',
        'property' => 'users[*].name',
    ));
```

***NOTE:*** You can use onlu one wildcard in your property option.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance48

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~160 days

Total

45

Last Release

389d ago

PHP version history (3 changes)v0.2.0PHP &gt;=7.2.19

v0.7.0PHP &gt;=7.4

v0.7.2PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bc133c80d03667c72f0576f0599d79159cd0fef8802c26855e75cb5f1322d31?d=identicon)[pawellen](/maintainers/pawellen)

---

Top Contributors

[![pawellen](https://avatars.githubusercontent.com/u/4718380?v=4)](https://github.com/pawellen "pawellen (82 commits)")

---

Tags

datatablesgridlisting

### Embed Badge

![Health badge](/badges/pawellen-listing/health.svg)

```
[![Health](https://phpackages.com/badges/pawellen-listing/health.svg)](https://phpackages.com/packages/pawellen-listing)
```

###  Alternatives

[sylius/grid-bundle

Amazing grids with support of filters and custom fields integrated into Symfony.

1358.3M44](/packages/sylius-grid-bundle)[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[mmucklo/grid-bundle

Datagrid for symfony2 or symfony3 or symfony4 or symfony5

21343.7k3](/packages/mmucklo-grid-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
