Skip to content

Commit 7bf6ad0

Browse files
fix sticky header, add yaml config, add phpDoc, fix ReadMe
1 parent 273cef1 commit 7bf6ad0

15 files changed

+575
-502
lines changed

README.md

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1-
# HelloBootstrapTable
1+
# HelloBootstrapTableBundle
22

33
**This Bundle provides *simple* [bootstrap-table](https://github.com/wenzhixin/bootstrap-table) configuration for your Doctrine Entities.**
44

55
Highly inspired by [SgDatatablesBundle](https://github.com/stwe/DatatablesBundle).
66

77
**The project is currently still under development. It can not be excluded that configuration changes.**
88

9-
10-
11-
## When should I not use HelloBootstrapTable
12-
13-
HelloBootstrapTable is designed for simple tables that are strongly bound to the entities. If you are creating highly customized tables with many formatters and a lot of client-side programming, HelloBootstrapTable is not suitable for that. However, you can of course use HelloBootstrapTable alongside your complex tables.
14-
15-
16-
179
## Overview
1810

1911
1. [Features](#features)
2012
2. [Installation](#installation)
2113
3. [Your First Table](#your-first-table)
2214
4. [Columns](#columns)
23-
5. [Table Props Configuration](#table-props)
24-
6. [Persistence Options Configuration](#persistence-options)
25-
15+
1. [TextColumn](#textcolumn)
16+
2. [BooleanColumn](#booleancolumn)
17+
3. [DateTimeColumn](#datetimecolumn)
18+
4. [HiddenColumn](#hiddencolumn)
19+
5. [ActionColumn](#actioncolumn)
20+
5. [Configuration](#configuration)
21+
1. [Table Dataset Options](#table-dataset-options)
22+
2. [Table Options](#table-options)
2623

2724
## Features
2825

29-
* Table Configuration in PHP
30-
* Filtering*
31-
* Sorting*
26+
* Create bootstrap-tables in PHP
27+
* Twig render function
28+
* global filtering*
29+
* column sorting*
3230
* Pagination*
33-
* Column Types: [TextColumn](#textcolumn), [BooleanColumn](#booleancolumn), [DateTimeColumn](#datetimecolumn), [ActionColumn](#actioncolumn), [HiddenColumn](#hiddencolumn)
31+
* different column types
32+
* bootstrap-table extensions
33+
* sticky-header
34+
* export
35+
* page-jump-to
36+
* toolbar
37+
* more in progress...
3438

3539
*server-side
3640

@@ -70,12 +74,6 @@ return [
7074
$ php bin/console assets:install --symlink
7175
```
7276

73-
``` bash
74-
# make a hard copy of assets in public/
75-
76-
$ php bin/console assets:install
77-
```
78-
7977
#### Add Assets into your base.html.twig
8078

8179
**CSS**:
@@ -124,7 +122,6 @@ use HelloSebastian\HelloBootstrapTableBundle\Columns\HiddenColumn;
124122
use HelloSebastian\HelloBootstrapTableBundle\Columns\ActionColumn;
125123
use HelloSebastian\HelloBootstrapTableBundle\Columns\BooleanColumn;
126124
use HelloSebastian\HelloBootstrapTableBundle\HelloBootstrapTable;
127-
use Symfony\Component\OptionsResolver\OptionsResolver;
128125

129126
class UserTable extends HelloBootstrapTable
130127
{
@@ -165,50 +162,26 @@ class UserTable extends HelloBootstrapTable
165162
->add("actions", ActionColumn::class, array(
166163
'title' => 'Actions',
167164
'width' => 150,
168-
'buttons' => array(
165+
'buttons' => array( //see ActionButton for more examples.
169166
array(
170167
'displayName' => 'open',
171168
'routeName' => 'show_user',
172-
'classNames' => 'btn btn-sm btn-success mr-1'
169+
'classNames' => 'btn btn-xs'
170+
'additionalClassNames' => 'btn-success mr-1'
173171
),
174172
array(
175173
'displayName' => 'edit',
176174
'routeName' => 'edit_user',
177-
'classNames' => 'btn btn-sm btn-warning'
175+
'classNames' => 'btn btn-xs btn-warning'
178176
)
179177
)
180178
));
181179
}
182180

183-
184181
protected function getEntityClass()
185182
{
186183
return User::class;
187184
}
188-
189-
//optional override of functions ...
190-
191-
public function configureTableDataset(OptionsResolver $resolver)
192-
{
193-
parent::configureTableDataset($resolver);
194-
195-
$resolver->setDefaults(array(
196-
'locale' => 'de-DE'
197-
));
198-
}
199-
200-
public function configureTableOptions(OptionsResolver $resolver)
201-
{
202-
parent::configureTableOptions($resolver);
203-
204-
$resolver->setDefaults(array(
205-
'bulkUrl' => $this->router->generate('bulk'),
206-
'bulkActions' => array(
207-
'edit' => 'Edit',
208-
'delete' => 'Delete'
209-
)
210-
));
211-
}
212185
}
213186
```
214187

@@ -252,17 +225,19 @@ public function index(Request $request, HelloBootstrapTableFactory $tableFactory
252225

253226
The Twig function will render a `table` with all attributes configured.
254227

228+
229+
255230
## Columns
256231

257232
### TextColumn
258233

259-
Represents column with text.
234+
Represents column with text. With formatter you can create complex columns.
260235

261236
#### Options
262237

263238
| Option | Type | Default | Description |
264239
| ---------- | -------------- | ------------------ | ------------------------------------------------------------ |
265-
| title | string / null | null | Set colum title. If no value is set, the specified attribute name is taken. |
240+
| title | string / null | null | Set column title. If no value is set, the specified attribute name is taken. |
266241
| field | string / null | null | Set internal field name for bootstrap-table. If no value is set, the specified attribute name is taken. |
267242
| width | integer / null | null | column width in px |
268243
| formatter | string | "defaultFormatter" | JavaScript function name for formatter. (see [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter)) |
@@ -287,8 +262,12 @@ Represents column with text.
287262
//you can return what ever you want ...
288263
return $user->getId() . " " . $user->getUsername();
289264
},
290-
'sortQuery' => function (QueryBuilder $qb, $direction) {
265+
'sort' => function (QueryBuilder $qb, $direction) { //execute if user sort this column
291266
$qb->addOrderBy('username', $direction);
267+
},
268+
'search' => function (QueryBuilder $qb, $search) { //execute if user use global search
269+
$qb->orWhere('user.username LIKE :username')
270+
->setParameter('username', $search . '%');
292271
}
293272
))
294273
```
@@ -383,12 +362,12 @@ All Options of TextColumn
383362

384363
| Option | Type | Default | Description |
385364
| ------- | ----- | ------- | ---------------------------------------- |
386-
| buttons | array | [] | array of buttons configuration as array. |
365+
| buttons | array | [ ] | array of buttons configuration as array. |
387366

388367
#### Example
389368

390369
```php
391-
->add(null, ActionColumn::class, array(
370+
->add("actions", ActionColumn::class, array( // key "actions" can be chosen freely.
392371
'title' => 'Actions',
393372
'width' => 120, //optional
394373
'buttons' => array(
@@ -400,7 +379,8 @@ All Options of TextColumn
400379
array(
401380
'displayName' => 'edit',
402381
'routeName' => 'edit_user',
403-
'additionalClassNames' => 'btn-success'
382+
// 'classNames' => 'btn btn-xs' (see below for more information)
383+
'additionalClassNames' => 'btn-warning'
404384
)
405385
)
406386
))
@@ -410,18 +390,30 @@ All Options of TextColumn
410390

411391
| Option | Type | Default | Description |
412392
| -------------------- | ------ | ----------- | ------------------------------------------------------------ |
413-
| displayName | string | "" | label of button in table |
393+
| displayName | string | "" | label of button |
414394
| routeName | string | "" | route name |
415395
| routeParams | array | array("id") | Array of property value names for the route parameters. By default is `id` set. |
416396
| classNames | string | "" | CSS class names which added directly to the `a` element. Overrides default class names from YAML config. |
417397
| additionalClassNames | string | "" | You can set default class names in YAML config. Then you can add additional class names to the button without override the default config. |
418398

399+
#### YAML Example
400+
401+
```yaml
402+
# config/packages/hello_table.yaml
403+
404+
hello_bootstrap_table:
405+
action_button_options:
406+
classNames: 'btn btn-xs'
407+
```
408+
409+
YAML config options are set to all buttons. If you want override global options from YAML config use `classNames` option.
410+
419411

420412

421413
## Configuration
422414

423415

424-
### Dataset Table Options
416+
### Table Dataset Options
425417

426418
Table Dataset are provided directly to the `bootstrap-table` as data-attributes and are a collection of setting options for the table.
427419

@@ -463,28 +455,27 @@ array(
463455

464456
#### Examples
465457

466-
Inside from Table class:
458+
**Inside from Table class:**
467459

468460
``` php
469461
// src/HelloTable/UserTable.php
470462
471463
class UserTable extends HelloBootstrapTable
472464
{
473465
...
474-
475-
protected function configureTableDataset(OptionsResolver $resolver)
466+
467+
protected function buildColumns(ColumnBuilder $builder, $options)
476468
{
477-
parent::configureTableProps($resolver);
478-
479-
$resolver->setDefaults(array(
469+
$this->setTableDataset(array(
480470
'locale' => 'de-DE'
481471
));
472+
473+
// ... $builder->add()
482474
}
483475
}
484476
```
485477

486-
487-
Outside from Table class:
478+
**Outside from Table class:**
488479

489480
``` php
490481
// src/Controller/UserController.php
@@ -502,17 +493,27 @@ public function index(Request $request, HelloBootstrapTableFactory $tableFactory
502493
}
503494
```
504495

496+
**YAML config:**
497+
498+
YAML config options are set to all tables. If you want override global options from YAML config use `setTableDataset` method in or outside from `HelloBootstrapTable`.
499+
500+
```yaml
501+
# config/packages/hello_table.yaml
502+
503+
hello_bootstrap_table:
504+
table_dataset_options:
505+
locale: 'de-DE'
506+
# ... (see options from Table Dataset Options)
507+
```
508+
505509

506-
In the `configureTableDataset` method, you can specify custom data that can be provided directly to the `bootstrap-table`.
507510

508511
### Table Options
509512

510513
All options that should not be provided directly as data-attributes of the table are managed here.
511514

512515
#### Options
513516

514-
With the Persistence Options you can set which settings (filtering, sorting, current page, ...) should be stored in the cookies. By default, all of them are activated.
515-
516517
| Option | Type | Default |
517518
| -------------------------- | ------ | ----------------- |
518519
| enableCheckbox | bool | true |
@@ -525,7 +526,7 @@ With the Persistence Options you can set which settings (filtering, sorting, cur
525526

526527
#### Examples
527528

528-
Inside from Table class:
529+
**Inside from Table class:**
529530

530531
``` php
531532
// src/HelloTable/UserTable.php
@@ -534,25 +535,18 @@ class UserTable extends HelloBootstrapTable
534535
{
535536
...
536537
537-
protected function configureTableOptions(OptionsResolver $resolver)
538+
protected function buildColumns(ColumnBuilder $builder, $options)
538539
{
539-
parent::configureTableOptions($resolver);
540-
541-
$resolver->setDefaults(array(
542-
'bulkUrl' => $this->router->generate('bulk'), //router are provided by HelloBootstrapTable
543-
// actions are display as select field
544-
// each option: value => display name
545-
'bulkActions' => array(
546-
'edit' => 'Edit',
547-
'delete' => 'Delete'
548-
)
540+
$this->setTableOptions(array(
541+
'enableCheckbox' => false
549542
));
543+
544+
// ... $builder->add()
550545
}
551546
}
552547
```
553548

554-
555-
Outside from Table class:
549+
**Outside from Table class:**
556550

557551
``` php
558552
// src/Controller/UserController.php
@@ -569,6 +563,19 @@ public function index(Request $request, HelloBootstrapTableFactory $tableFactory
569563
}
570564
```
571565

566+
**YAML config:**
567+
568+
YAML config options are set to all tables. If you want override global options from YAML config use `setTableDataset` method in or outside from `HelloBootstrapTable`.
569+
570+
```yaml
571+
# config/packages/hello_table.yaml
572+
573+
hello_bootstrap_table:
574+
table_options:
575+
enableCheckbox: false
576+
# ... (see options Table Options)
577+
```
578+
572579

573580

574581
## ToDo's

0 commit comments

Comments
 (0)