2017 © Pedro Peláez
 

library datatable-bundle

provide datatable server side request easily

image

fys/datatable-bundle

provide datatable server side request easily

  • Monday, November 7, 2016
  • by farizsyahputra
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Datatable Bundle for Symfony

Datatable Bundle provides you a capabilitiy to handle Server Side Processing Datatables, (*1)

Installation

install via composer, (*2)

composer require fys/datatable-bundle

activate the bundle in AppKernel.php, (*3)

$bundles = [
    ....
    new FYS\DatatableBundle\FYSDatatableBundle(),
]

Creating your first Datatable Server Side

lets say you have an entity class like this, (*4)

<?php
// src/AppBundle/Entity/People.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * People
 *
 * @ORM\Table(name="people")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\PeopleRepository")
 */
class People
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="address", type="string", length=255)
     */
    private $address;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return People
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set address
     *
     * @param string $address
     *
     * @return People
     */
    public function setAddress($address)
    {
        $this->address = $address;

        return $this;
    }

    /**
     * Get address
     *
     * @return string
     */
    public function getAddress()
    {
        return $this->address;
    }
}

now, let's create some table. At this point, please make sure you already import jquery, datatable css and datatable js, (*5)

// src/AppBundle/Resources/views/people.html.twig


NAME ADDRESS

Ok, now we move to the Controller, (*6)

// src/AppBundle/Controller/DefaultController.php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

class DefaultController extends Controller
{
    /**
     * @Route("/people", name="people")
     */
    public function indexAction(Request $request)
    {
        return $this->render('AppBundle::people.html.twig', array());
    }

    /**
     * @Route("/people/data", name="people_data")
     * @Method("POST")
     */
    public function peopleDataAction(Request $request)
    {
        // call the service first.
        $datatable = $this->get('fys.dt.handle_request');

        // this is where the magic starts.
        // process() method has 3 parameters that should be filled.
        // first, Request $request Symfony\Component\HttpFoundation\Request Object
        // second, String Entity Class
        // third, array $columns, the ordered lists of field in the datatable table
        $response = $datatable->process($request, 'AppBundle:People', array('name', 'address'));

        // return JsonResponse object
        return new JsonResponse($response);
    }
}

you just create your first datatable server side, (*7)

The Versions

07/11 2016

dev-master

9999999-dev

provide datatable server side request easily

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

07/11 2016

dev-develop

dev-develop

provide datatable server side request easily

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

07/11 2016

v1.0.1

1.0.1.0

provide datatable server side request easily

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

07/11 2016

1.0.0

1.0.0.0

provide datatable server side request easily

  Sources   Download

MIT

The Requires

  • php >=5.3.0