Skip to content

Commit f4e2075

Browse files
Feature/advanced search (#2)
* add advanced search, fix option "searchable" in columns * fix typo
1 parent 3b467e8 commit f4e2075

File tree

9 files changed

+188
-113
lines changed

9 files changed

+188
-113
lines changed

README.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ Highly inspired by [SgDatatablesBundle](https://github.com/stwe/DatatablesBundle
3131
* Pagination*
3232
* different column types
3333
* bootstrap-table extensions
34-
* sticky-header
35-
* export
36-
* page-jump-to
37-
* toolbar
34+
* [sticky-header](https://bootstrap-table.com/docs/extensions/sticky-header/)
35+
* [export](https://bootstrap-table.com/docs/extensions/export/)
36+
* [page-jump-to](https://bootstrap-table.com/docs/extensions/page-jump-to/)
37+
* [toolbar](https://bootstrap-table.com/docs/extensions/toolbar/) with [advanced-search](https://bootstrap-table.com/docs/extensions/toolbar/#advancedsearch)
3838
* more in progress...
3939

4040
*server-side
@@ -245,7 +245,7 @@ Represents column with text. With formatter you can create complex columns.
245245
| class | string / null | null | The column class name. |
246246
| formatter | string / null | null | JavaScript function name for formatter. (see [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter)) |
247247
| footerFormatter | string / null | null | JavaScript function name for footer formatter. |
248-
| filterable | bool | true | enable / disable filtering for this column |
248+
| searchable | bool | true | enable / disable filtering for this column |
249249
| sortable | bool | true | enable / disable sortable for this column |
250250
| switchable | bool | true | enable / disable interactive hide and show of column. |
251251
| visible | bool | true | show / hide column |
@@ -262,25 +262,25 @@ Represents column with text. With formatter you can create complex columns.
262262

263263
```php
264264
//use statements for search and sort option
265-
use Doctrine\ORM\Query\Expr\Orx;
265+
use Doctrine\ORM\Query\Expr\Composite;
266266
use Doctrine\ORM\QueryBuilder;
267267

268268
->add('username', TextColumn::class, array(
269269
'title' => 'Username',
270270
'emptyData' => "No Username found.",
271271

272-
//optional overrides ...
272+
//optional overrides ...
273273
'data' => function (User $user) { //entity from getEntityClass
274274
//you can return what ever you want ...
275275
return $user->getId() . " " . $user->getUsername();
276276
},
277277
'sort' => function (QueryBuilder $qb, $direction) { //execute if user sort this column
278278
$qb->addOrderBy('username', $direction);
279279
},
280-
'search' => function (Orx $orx, QueryBuilder $qb, $dql, $search, $key) {
281-
//first add condition to $orx
280+
'search' => function (Composite $composite, QueryBuilder $qb, $dql, $search, $key) {
281+
//first add condition to $composite
282282
//don't forget the '?' before $key
283-
$orx->add($qb->expr()->like($dql, '?' . $key));
283+
$composite->add($qb->expr()->like($dql, '?' . $key));
284284

285285
//then bind search to query
286286
$qb->setParameter($key, '%' . $search . '%');
@@ -292,13 +292,13 @@ use Doctrine\ORM\QueryBuilder;
292292

293293
The search option seems a bit complicated at first, but it allows full control over the query in the column.
294294

295-
| Paramenter name | Description |
296-
| ------------------ | ------------------------------------------------------------ |
297-
| `Orx $orx` | All columns are connected to the SQL query or. With `$orx` more parts can be added to the query. |
298-
| `QueryBuilder $qb` | `$qb` holds the use QueryBuilder. It is the same instance as can be queried with `getQueryBuilder()` in the table class. |
299-
| `(string) $dql` | `$dql` represents the "path" to the variable in the query (e.g. `user.username` or in case of a JOIN `costCentre.name`) |
300-
| `$search` | The search in the type of a string. |
301-
| `$key` | The index of the columns already gone through. The index is used for parameter binding to the query. |
295+
| Paramenter name | Description |
296+
| ---------------------- | ------------------------------------------------------------ |
297+
| `Composite $composite` | In the global search all columns are connected as or. In the advanced search all columns are combined with an and-connection. With `$composite` more parts can be added to the query. |
298+
| `QueryBuilder $qb` | `$qb` holds the use QueryBuilder. It is the same instance as can be queried with `getQueryBuilder()` in the table class. |
299+
| `$dql` | `$dql` represents the "path" to the variable in the query (e.g. `user.username` or in case of a JOIN `costCentre.name`) |
300+
| `$search` | The search in the type of a string. |
301+
| `$key` | The index of the columns already gone through. The index is used for parameter binding to the query. |
302302

303303

304304

@@ -362,16 +362,14 @@ Represents column that are not visible in the table. Can used for data which are
362362

363363
All Options of TextColumn.
364364

365-
`filterable`, `sortable`, `visible` and `switchable` are disabled by default.
365+
`searchable`, `sortable`, `visible` and `switchable` are disabled by default.
366366

367367
#### Example
368368

369369
```php
370370
->add("id", HiddenColumn::class)
371371
```
372372

373-
ID is used for bulk actions and must therefore be sent along, but should not be visible in the table.
374-
375373

376374

377375
### ActionColumn
@@ -382,7 +380,7 @@ Represents column for action buttons (show / edit / remove ...).
382380

383381
All Options of TextColumn
384382

385-
`sortable`, `filterable` and `switchable` are disable by default.
383+
`sortable`, `searchable` and `switchable` are disable by default.
386384

387385
`formatter` is set to `defaultActionFormatter`. `cellStyle` is set to `defaultActionCellStyle`.
388386

@@ -447,29 +445,31 @@ Table Dataset are provided directly to the `bootstrap-table` as data-attributes
447445

448446
#### Options
449447

450-
| Option | Type | Default |
451-
| -------------------------- | ------ | ---------------------------------- |
452-
| pagination | bool | true |
453-
| search | bool | true |
454-
| show-columns | bool | true |
455-
| show-footer | bool | true |
456-
| show-refresh | bool | true |
457-
| toolbar | string | "#toolbar" |
458-
| page-list | string | "[10, 25, 50, 100, 200, 500, All]" |
459-
| page-size | int | 25 |
460-
| sort-reset | bool | true |
461-
| pagination-V-Align | string | "both" |
462-
| undefined-text | string | "" |
463-
| locale | string | "en-US" |
464-
| click-to-select | bool | true |
465-
| show-jump-to | bool | true |
466-
| show-export | bool | true |
467-
| export-types | string | "['csv', 'txt'', 'excel']" |
468-
| export-options | array | see under table* |
469-
| sticky-header | bool | true |
470-
| sticky-header-offset-left | int | 0 |
471-
| sticky-header-offset-right | int | 0 |
472-
| sticky-header-offset-y | int | 0 |
448+
| Option | Type | Default |
449+
| -------------------------- | ------ | ----------------------------------------------------------- |
450+
| pagination | bool | true |
451+
| search | bool | true |
452+
| show-columns | bool | true |
453+
| show-footer | bool | true |
454+
| show-refresh | bool | true |
455+
| toolbar | string | "#toolbar" |
456+
| page-list | string | "[10, 25, 50, 100, 200, 500, All]" |
457+
| page-size | int | 25 |
458+
| sort-reset | bool | true |
459+
| pagination-V-Align | string | "both" |
460+
| undefined-text | string | "" |
461+
| locale | string | "en-US" |
462+
| advanced-search | bool | true |
463+
| id-table | string | class name of table with counter. (`$this->getTableName()`) |
464+
| click-to-select | bool | true |
465+
| show-jump-to | bool | true |
466+
| show-export | bool | true |
467+
| export-types | string | "['csv', 'txt'', 'excel']" |
468+
| export-options | array | see under table* |
469+
| sticky-header | bool | true |
470+
| sticky-header-offset-left | int | 0 |
471+
| sticky-header-offset-right | int | 0 |
472+
| sticky-header-offset-y | int | 0 |
473473

474474
`export-options`:
475475

src/Columns/AbstractColumn.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ public function isAssociation()
180180
return (false !== strpos($this->dql, "."));
181181
}
182182

183+
public function isSearchable()
184+
{
185+
return $this->outputOptions['searchable'];
186+
}
187+
183188
public function getColumnBuilder()
184189
{
185190
return $this->columnBuilder;
@@ -214,7 +219,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)
214219
'valign' => null,
215220
'falign' => null,
216221
'order' => "asc",
217-
'filterable' => true,
222+
'searchable' => true,
218223
'sortable' => true,
219224
'visible' => true,
220225
'switchable' => true,
@@ -236,7 +241,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)
236241
$resolver->setAllowedTypes('valign', ['string', 'null']);
237242
$resolver->setAllowedTypes('falign', ['string', 'null']);
238243

239-
$resolver->setAllowedTypes('filterable', ['boolean']);
244+
$resolver->setAllowedTypes('searchable', ['boolean']);
240245
$resolver->setAllowedTypes('sortable', ['boolean']);
241246
$resolver->setAllowedTypes('visible', ['boolean']);
242247
$resolver->setAllowedTypes('switchable', ['boolean']);

src/Columns/ActionColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)
1717
"buttons" => array(),
1818
"sortable" => false,
1919
"switchable" => false,
20-
"filterable" => false,
20+
"searchable" => false,
2121
"formatter" => "defaultActionFormatter",
2222
"cellStyle" => "defaultActionCellStyle"
2323
));

src/Columns/HiddenColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)
1313
parent::configureOutputOptions($resolver);
1414

1515
$resolver->setDefaults(array(
16-
'filterable' => false,
16+
'searchable' => false,
1717
'sortable' => false,
1818
'visible' => false,
1919
'switchable' => false

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ private function addTableDatasetOptions()
8989
->scalarNode('pagination-V-Align')->end()
9090
->scalarNode('undefined-text')->end()
9191
->scalarNode('locale')->end()
92+
->booleanNode('advanced-search')->end()
93+
->scalarNode('id-table')->end()
9294
->booleanNode('click-to-select')->end()
9395
->booleanNode('show-jump-to')->end()
9496
->booleanNode('show-export')->end()

src/HelloBootstrapTable.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public function __construct(RouterInterface $router, EntityManagerInterface $em,
9090
}
9191

9292
/**
93-
*
94-
*
9593
* @param ColumnBuilder $builder
9694
* @param array $options
9795
*/
@@ -241,6 +239,8 @@ protected function configureTableDataset(OptionsResolver $resolver)
241239
"pagination-V-Align" => "both",
242240
"undefined-text" => "",
243241
"locale" => "en-US",
242+
"advanced-search" => true,
243+
"id-table" => $this->getTableName(),
244244

245245
//extensions
246246
"click-to-select" => true,
@@ -274,6 +274,8 @@ protected function configureTableDataset(OptionsResolver $resolver)
274274
$resolver->setAllowedTypes("pagination-V-Align", ["string"]);
275275
$resolver->setAllowedTypes("undefined-text", ["string"]);
276276
$resolver->setAllowedTypes("locale", ["string"]);
277+
$resolver->setAllowedTypes("advanced-search", ["bool"]);
278+
$resolver->setAllowedTypes("id-table", ["string"]);
277279
$resolver->setAllowedTypes("click-to-select", ["bool"]);
278280
$resolver->setAllowedTypes("show-jump-to", ["bool"]);
279281
$resolver->setAllowedTypes("show-export", ["bool"]);

0 commit comments

Comments
 (0)