Skip to content

Commit 6250613

Browse files
committed
Update docs
1 parent 6fcd03e commit 6250613

File tree

3 files changed

+75
-61
lines changed

3 files changed

+75
-61
lines changed

README.md

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,18 @@
99
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/05d79ba2-cba4-4201-a17a-2868c51f9c6c.svg)](https://insight.sensiolabs.com/projects/05d79ba2-cba4-4201-a17a-2868c51f9c6c)
1010

1111
This bundle provides convenient integration of the popular [DataTables](https://datatables.net/) jQuery library
12-
for realtime AJAX tables in your Symfony 3.3+ or 4.0+ application. Older versions of Symfony [will not be supported](https://github.com/omines/datatables-bundle/issues/1).
12+
for realtime Ajax tables in your Symfony 3.3+ or 4.0+ application.
1313

1414
Unlike other bundles providing similar functionality we decoupled the implementation of the DataTables logic
1515
completely from the source of the data. Therefore it is possible to implement your own custom adapters for
1616
every possible data source. Doctrine ORM comes bundled already, we intend to provide popular choices like
1717
Elastica, Doctrine DBAL and MongoDB out of the box as well.
1818

19-
## Installation
19+
## Documentation
2020

21-
To install, use composer:
21+
[Visit the documentation with extensive code samples](https://omines.github.io/datatables-bundle/).
2222

23-
```bash
24-
$ composer require omines/datatables-bundle
25-
```
26-
Then add the bundle to your kernel's bundle registration:
27-
```php
28-
public function registerBundles()
29-
{
30-
...
31-
new \Omines\DataTablesBundle\DataTablesBundle(),
32-
...
33-
}
34-
```
35-
36-
## Usage
37-
38-
To render the most basic table with predefined data, implement a controller like this:
39-
```php
40-
use Omines\DataTablesBundle\DataTablesTrait;
41-
use Omines\DataTablesBundle\Adapter\ArrayAdapter;
42-
use Omines\DataTablesBundle\Column\TextColumn;
43-
44-
class MyController
45-
{
46-
use DataTablesTrait;
47-
48-
public function showAction(Request $request)
49-
{
50-
$table = $this->createDataTable()
51-
->add('firstName', TextColumn::class)
52-
->add('lastName', TextColumn::class)
53-
->createAdapter(ArrayAdapter::class, [
54-
['firstName' => 'Donald', 'lastName' => 'Trump'],
55-
['firstName' => 'Barack', 'lastName' => 'Obama'],
56-
])
57-
->handleRequest($request);
58-
59-
if ($request->isXmlHttpRequest()) {
60-
return $table->getResponse();
61-
}
62-
63-
$this->render('list.html.twig', ['datatable' => $table]);
64-
}
65-
}
66-
67-
```
68-
Now in your Twig template render the required HTML and JS with:
69-
```twig
70-
{{ datatable(datatable)) }}
71-
```
23+
The documentation below is pending move to the external site.
7224

7325
#### Making a separate datatable type
7426

docs/source/index.html.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ class MyController extends Controller
7777
```
7878
This trivial bit of code in your controller prepares a fully functional DataTables instance for use.
7979

80-
The <code>DataTablesTrait</code> is included to expose 2 methods in your controller for easy instantiation.
81-
The `createDataTable` function is used in this example, the other one will be covered later. On the DataTable
82-
instance we add 2 columns of type `TextColumn`, and we bind it to an adapter providing a static array as the
80+
The optional <code>DataTablesTrait</code> is included to expose convenience methods in your controller for
81+
easy instantiation. The `createDataTable` function is used in this example. On the DataTable instance we
82+
add 2 columns of type `TextColumn`, and we bind it to an adapter providing a static array as the
8383
source of the data.
8484

85-
The `handleRequest` function will take care of handling any postbacks, similar to how Symfony's Form component
85+
The `handleRequest` function will take care of handling any callbacks, similar to how Symfony's Form component
8686
works. If it turns out the request originated from a callback we let the table provide the controller response,
8787
otherwise we render a template with the table provided as a parameter.
8888

@@ -111,9 +111,67 @@ string with the configured settings required for initialization.
111111

112112
And that's it, the library will take it from here and your table will be shown on your webpage!
113113

114-
# Options
114+
# Configuration
115115

116-
Option | Default | Description
117-
------ | ------- | -----------
118-
name | dt | The name of the DataTable. Used mainly to separate callbacks in case multiple tables are used on the same page.
116+
```yaml
117+
datatables:
119118

119+
# Load i18n data from DataTables CDN or locally
120+
language_from_cdn: true
121+
122+
# Persist request state automatically
123+
request_state: true
124+
125+
# Default class attribute to apply to the root table elements
126+
class_name: ~
127+
128+
# Default HTTP method to be used for callbacks
129+
method: POST # One of "GET"; "POST"
130+
131+
# Default translation domain to be used
132+
translation_domain: messages
133+
134+
# If and where to enable the DataTables Filter module
135+
column_filter: null # One of "thead"; "tfoot"; "both"; null
136+
137+
# Default options to load into DataTables
138+
options:
139+
# Default table options
140+
141+
# Default template to be used for DataTables HTML
142+
template: ~
143+
144+
# Default service used to render templates
145+
renderer: Omines\DataTablesBundle\Twig\TwigRenderer
146+
```
147+
148+
Global configuration of the bundle is done in your config file. The default configuration is shown here,
149+
and should be fine in most cases. Most settings can be overridden per table, but for most applications
150+
you will want to make changes at the global level so they are applied everywhere, providing a uniform
151+
look and feel.
152+
153+
The following settings only exist at the configuration level:
154+
155+
Option | Type | Description
156+
------ | ---- | ------- | -----------
157+
template | string | Default template to be used for rendering the basic HTML table in your templates.
158+
renderer | string | Service used to render the table HTML, which must implement the <code>DataTableRendererInterface</code>.
159+
160+
The other settings correspond to table level settings, and the `options` are passed (almost) verbatim
161+
to the DataTables clientside constructor. Refer to the sections below for details on individual settings
162+
and options.
163+
164+
## Settings
165+
166+
These settings can all be defined both at the global config level and overridden per table.
167+
168+
Setting | Type | Default | Description
169+
------- | ---- | ------- | -----------
170+
name | string | dt | The name of the DataTable. Used mainly to separate callbacks in case multiple tables are used on the same page.
171+
method | string | POST | Use `GET` or `POST` to define the HTTP method used by callbacks.
172+
class_name | string | | Class to apply to the `<table>` element in generated tables. Separate multiple classes with a space.
173+
column_filter | string | *null* | When using column level filters set this to `thead`, `tfoot` or `both` to specify where to render them.
174+
language_from_cdn | bool | true | Either loads DataTables' own translations from CDN (default) or have them provided by your own Symfony translation files.
175+
translation_domain | string | messages | Default translation domain used in the table structure.
176+
177+
## Options

tests/Fixtures/AppBundle/Controller/CustomQueryController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Omines\DataTablesBundle\Controller\DataTablesTrait;
1616
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1717
use Symfony\Component\HttpFoundation\Request;
18+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1819
use Tests\Fixtures\AppBundle\DataTable\Type\CustomQueryTableType;
1920

2021
/**
@@ -29,7 +30,10 @@ class CustomQueryController extends Controller
2930
public function tableAction(Request $request)
3031
{
3132
$datatable = $this->createDataTableFromType(CustomQueryTableType::class, [], ['method' => Request::METHOD_GET]);
33+
if ($datatable->handleRequest($request)->isCallback()) {
34+
return $datatable->getResponse();
35+
}
3236

33-
return $datatable->handleRequest($request)->getResponse();
37+
throw new NotFoundHttpException('This exception must never be triggered');
3438
}
3539
}

0 commit comments

Comments
 (0)