zephyrhq / vue_datatable_bundle
Bundle for server processing of vue-table2 lib
dev-master
2018-11-19 00:51 UTC
Requires
- php: >=7.2
- symfony/config: ^4.1
- symfony/dependency-injection: ^4.1
- symfony/http-foundation: ^4.1
- symfony/http-kernel: ^4.1
- symfony/routing: ^4.1
This package is auto-updated.
Last update: 2024-11-19 14:40:57 UTC
README
Installation
composer require zephyrhq/vue_datatable_bundle
Configuration
vue_datatable: # The vue-table2 server processing route vue_table2_route_name: vuetable2_process
Usage
With Manager
public function productDataAction(Request $request): Response { $datatable = $this->get(Datatable{Manager|Provider|Factory|Builder}::class)->getDatatable(DatatableType::class); return $datatable->handleRequest($request)->getResponse(); }
Directly In controller
Create a provider that is responsible to retrieve the data from a database or whatever, juste implements the DatatableProviderInterface.
namespace App\DatatableProvider; use VueDatatableBundle\Domain\Datatable; use VueDatatableBundle\Domain\Provider\ArrayResultSet; use VueDatatableBundle\Domain\Provider\DatatableProviderInterface; use VueDatatableBundle\Domain\Provider\ResultSetInterface; class ProductProvider implements DatatableProviderInterface { public function getResult(Datatable $datatable): ResultSetInterface { $datatableRequest = $datatable->getRequest(); // from a database or whatever $data = [ [ 'id' => '1', 'name' => 'Sofa', 'price' => 102.99, 'vat' => 0.2, 'availableQuantity' => 50, ], [ 'id' => '2', 'name' => 'Table', 'price' => 50.65, 'vat' => 0.2, 'availableQuantity' => 3, ], [ 'id' => '3', 'name' => 'TV', 'price' => 550.0, 'vat' => 0.2, 'availableQuantity' => 999, ], ]; return new ArrayResultSet($data, \count($data), \count($data)); } }
In a controller :
public function vuetable2Process(Request $request, DatatableInteractorInterface $datatableInteractor, ProductProvider $productProvider): Response { $datatable = (new Datatable()) ->addColumn(new StringColumn('toto')) ->addColumn(new StringColumn('description')) ->setProvider($productProvider) ; $dtResult = $datatableInteractor->handleRequest($datatable, $request); $response = $datatableInteractor->createResponse($datatable, $dtResult); return $response; }