Coder Social home page Coder Social logo

doctrine-datatables's Introduction

Doctrine Datatables library Build Status

Doctrine Datatables library provides a Doctrine2 server side processing for Datatables.

This library was created because existing libraries lack of flexibility around field types and field filtering. This library does not provide any JavaScript code generation nor datatables.js sources, you need to install and run datatables.js yourself.

Installation

You can install this library using composer

composer require neurosys/doctrine-datatables

or add the package name to your composer.json

"require": {
    ...
    "neurosys/doctrine-datatables": "dev-master"
}

Features

  • support of doctrine query builder
  • support of column search with custom column definitions (ex. number, date, composed fields)

It does not support global search (yet)

Usage

$builder = new TableBuilder($entityManager, $_GET);
$builder
    ->from('Foo\Bar\Entity\Sample', 's')
    ->add('text', 's.name')      // field name will be resolved from request (mDataProp_X)
    ->add('number', 's.price')   // field will be a number field which can be filtered by value range
    ->add('boolean', 's.active')
    ;

$response = $builder->getTable()
    ->getResponseArray('entity') // hydrate entity, defaults to array
    ;

// now you can simply return a response
// header ('Content-Type', 'application/json');
// echo json_encode($response);

Composed fields example:

$builder
    ->from('Foo\Bar\Entity\Sample', 's')
    ->join('s.user', 'u')
    ->add('text', 's.name')                          // select and filter by a name field
    ->add('text', 'u.firstName, u.lastName', 'u.id') // select firstName and lastName but filter by an id field
    ->add('date')
    ;

Custom query builder example:

$responseArray = $builder
    ->setQueryBuilder($customQueryBuilder)
    ->add('text', 's.foo', 's.bar') // select foo field but filter by a bar field
    ->getTable()
    ->getResponseArray();

Available field types

  • text
  • number
  • date
  • boolean
  • choice

Twig field rendering

Default renderer is PhpRenderer, this can be changed by passing another renderer as 4th argument to the TableBuilder:

new TableBuilder($entityManager, $_GET, null, new TwigRenderer($twigEnvironment));

To set field template pass template option:

$builder
    ->add('date', 's.createdAt', null, array(
        'template' => 'path/to/template.html.twig'
    ))

In template.html.twig

{{ value | date }}

Warning

This library is still in development, API is most likely to change.

License

Doctrine Datatables is licensed under the MIT license.

doctrine-datatables's People

Contributors

bpasinski-neurosys avatar hellomedia avatar neurosys-public avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.