PHP code example of pawellen / listing

1. Go to this page and download the library: Download pawellen/listing 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/ */

    

pawellen / listing example snippets


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


2,5. Configuration:

data_tables_listing:
    default_template: LenPanelBundle::listing_div_layout.html.twig
    s twig function.
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()
        );
    }

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',
            'erface $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';
    }
}

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

    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');
            }
        ));
    }

    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');
            }
        ));
    }

    $builder->add('name', 'text', array(
        'label' => 'User name',
        '       'eval' => '%like%'
        )
    ))

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

     // DEPRECATED:
     $builder->add('country', 'text', array(
         'label' => 'Country name',
         '%',
             'join' => array(
                 array('field' => 'u.address', 'alias' => 'a'),
                 array('field' => 'a.country', 'alias' => 'c'),
             )
         )
     ))

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

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

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

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