Skip to content

Commit 3b467e8

Browse files
Merge pull request #1 from HelloSebastian/query-add-options
fix query, add column and table options, update readme
2 parents 08dae54 + d52a19d commit 3b467e8

9 files changed

Lines changed: 81 additions & 35 deletions

File tree

README.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,27 @@ Represents column with text. With formatter you can create complex columns.
236236

237237
#### Options
238238

239-
| Option | Type | Default | Description |
240-
| ---------- | -------------- | ------------------ | ------------------------------------------------------------ |
241-
| title | string / null | null | Set column title. If no value is set, the specified attribute name is taken. |
242-
| field | string / null | null | Set internal field name for bootstrap-table. If no value is set, the specified attribute name is taken. |
243-
| width | integer / null | null | column width in px |
244-
| formatter | string | "defaultFormatter" | JavaScript function name for formatter. (see [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter)) |
245-
| filterable | bool | true | enable / disable filtering for this column |
246-
| sortable | bool | true | enable / disable sortable for this column |
247-
| switchable | bool | true | enable / disable interactive hide and show of column. |
248-
| visible | bool | true | show / hide column |
249-
| emptyData | string | "" | default value if attribute from entity is null |
250-
| sort | Closure / null | null | custom sort query callback (see example) |
251-
| filter | Closure / null | null | custom filter query callback (see example) |
252-
| data | Closure / null | null | custom data callback (see example) |
239+
| Option | Type | Default | Description |
240+
| --------------- | -------------- | ------- | ------------------------------------------------------------ |
241+
| title | string / null | null | Set column title. If no value is set, the specified attribute name is taken. |
242+
| field | string / null | null | Set internal field name for bootstrap-table. If no value is set, the specified attribute name is taken. |
243+
| width | integer / null | null | column width in px |
244+
| widthUnit | string | "px" | Unit of width. |
245+
| class | string / null | null | The column class name. |
246+
| formatter | string / null | null | JavaScript function name for formatter. (see [formatter](https://bootstrap-table.com/docs/api/column-options/#formatter)) |
247+
| footerFormatter | string / null | null | JavaScript function name for footer formatter. |
248+
| filterable | bool | true | enable / disable filtering for this column |
249+
| sortable | bool | true | enable / disable sortable for this column |
250+
| switchable | bool | true | enable / disable interactive hide and show of column. |
251+
| visible | bool | true | show / hide column |
252+
| emptyData | string | "" | default value if attribute from entity is null |
253+
| sort | Closure / null | null | custom sort query callback (see example) |
254+
| filter | Closure / null | null | custom filter query callback (see example) |
255+
| data | Closure / null | null | custom data callback (see example) |
256+
| align | string / null | null | Indicate how to align the column data. `'left'`, `'right'`, `'center'` can be used. |
257+
| halign | string / null | null | Indicate how to align the table header. `'left'`, `'right'`, `'center'` can be used. |
258+
| valign | string / null | null | Indicate how to align the cell data. `'top'`, `'middle'`, `'bottom'` can be used. |
259+
| falign | string / null | null | Indicate how to align the table footer. `'left'`, `'right'`, `'center'` can be used. |
253260

254261
#### Example
255262

@@ -377,7 +384,7 @@ All Options of TextColumn
377384

378385
`sortable`, `filterable` and `switchable` are disable by default.
379386

380-
`formatter` is set to `defaultActionFormatter`.
387+
`formatter` is set to `defaultActionFormatter`. `cellStyle` is set to `defaultActionCellStyle`.
381388

382389
**And:**
383390

@@ -534,14 +541,15 @@ All options that should not be provided directly as data-attributes of the table
534541

535542
#### Options
536543

537-
| Option | Type | Default |
538-
| -------------------------- | ------ | ----------------- |
539-
| enableCheckbox | bool | true |
540-
| bulkUrl | string | "" |
541-
| bulkActionSelectClassNames | string | "form-control" |
542-
| bulkActions | array | [ ] |
543-
| bulkButtonName | string | "Okay" |
544-
| bulkButtonClassNames | string | "btn btn-primary" |
544+
| Option | Type | Default |
545+
| -------------------------- | ------ | ------------------------------- |
546+
| tableClassNames | string | "table table-stripped table-sm" |
547+
| enableCheckbox | bool | true |
548+
| bulkUrl | string | "" |
549+
| bulkActionSelectClassNames | string | "form-control" |
550+
| bulkActions | array | [ ] |
551+
| bulkButtonName | string | "Okay" |
552+
| bulkButtonClassNames | string | "btn btn-primary" |
545553

546554

547555
#### Examples

assets/app.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ require("bootstrap-table/dist/extensions/export/bootstrap-table-export.min");
2121

2222
$(function () {
2323

24-
window.defaultFormatter = function (value) {
25-
return value;
26-
};
27-
2824
window.defaultActionFormatter = function (value) {
29-
const $wrapper = $("<div />");
25+
const $wrapper = $("<div>");
3026

3127
for (let i = 0; i < value.length; i++) {
3228
const $button = $('<a />');
@@ -35,10 +31,17 @@ $(function () {
3531
$button.html(value[i].displayName);
3632
$wrapper.append($button);
3733
}
38-
3934
return $wrapper.html();
4035
};
4136

37+
window.defaultActionCellStyle = function () {
38+
return {
39+
css: {
40+
display: 'inline-block'
41+
}
42+
};
43+
};
44+
4245
const $table = $(".hello-bootstrap-table");
4346

4447
if ($table.length) {

src/Columns/AbstractColumn.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@ public function replaceOption($key, $value)
126126
$this->setOptions($options);
127127
}
128128

129-
public function getOutputOptions()
129+
public function getOutputOptions($filterNulls = true)
130130
{
131+
if ($filterNulls) {
132+
$outputOptions = $this->outputOptions;
133+
134+
return array_filter($outputOptions, function ($value) {
135+
return !is_null($value);
136+
});
137+
}
138+
131139
return $this->outputOptions;
132140
}
133141

@@ -198,21 +206,43 @@ protected function configureOutputOptions(OptionsResolver $resolver)
198206
'title' => null,
199207
'field' => null,
200208
'width' => null,
209+
'widthUnit' => "px",
210+
'cellStyle' => null,
211+
'class' => null,
212+
'align' => null,
213+
'halign' => null,
214+
'valign' => null,
215+
'falign' => null,
216+
'order' => "asc",
201217
'filterable' => true,
202218
'sortable' => true,
203219
'visible' => true,
204220
'switchable' => true,
205-
'formatter' => "defaultFormatter"
221+
'formatter' => null,
222+
'footerFormatter' => null
206223
));
207224

208225
$resolver->setAllowedTypes('title', ['string', 'null']);
209226
$resolver->setAllowedTypes('field', ['string', 'null']);
210227
$resolver->setAllowedTypes('width', ['integer', 'null']);
228+
$resolver->setAllowedTypes('widthUnit', ['string']);
229+
$resolver->setAllowedTypes('order', ['string']);
230+
231+
$resolver->setAllowedTypes('cellStyle', ['string', 'null']);
232+
$resolver->setAllowedTypes('class', ['string', 'null']);
233+
234+
$resolver->setAllowedTypes('align', ['string', 'null']);
235+
$resolver->setAllowedTypes('halign', ['string', 'null']);
236+
$resolver->setAllowedTypes('valign', ['string', 'null']);
237+
$resolver->setAllowedTypes('falign', ['string', 'null']);
238+
211239
$resolver->setAllowedTypes('filterable', ['boolean']);
212240
$resolver->setAllowedTypes('sortable', ['boolean']);
213241
$resolver->setAllowedTypes('visible', ['boolean']);
214242
$resolver->setAllowedTypes('switchable', ['boolean']);
243+
215244
$resolver->setAllowedTypes('formatter', ['string', 'null']);
245+
$resolver->setAllowedTypes('footerFormatter', ['string', 'null']);
216246
}
217247

218248
}

src/Columns/ActionColumn.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ protected function configureOutputOptions(OptionsResolver $resolver)
1818
"sortable" => false,
1919
"switchable" => false,
2020
"filterable" => false,
21-
"formatter" => "defaultActionFormatter"
21+
"formatter" => "defaultActionFormatter",
22+
"cellStyle" => "defaultActionCellStyle"
2223
));
2324

2425
$resolver->setRequired('buttons');

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private function addTableOptions()
5353
->addDefaultsIfNotSet()
5454
->normalizeKeys(false)
5555
->children()
56+
->scalarNode('tableClassNames')->end()
5657
->booleanNode('enableCheckbox')->end()
5758
->scalarNode('bulkUrl')->end()
5859
->scalarNode('bulkActionSelectClassNames')->end()

src/HelloBootstrapTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ protected function configureTableDataset(OptionsResolver $resolver)
296296
protected function configureTableOptions(OptionsResolver $resolver)
297297
{
298298
$resolver->setDefaults(array(
299+
'tableClassNames' => 'table table-striped table-sm',
299300
'enableCheckbox' => true,
300301
'bulkUrl' => '',
301302
'bulkActionSelectClassNames' => 'form-control',

src/Query/DoctrineQueryBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ public function fetchData($requestData)
126126
}
127127
}
128128

129-
$this->qb->andWhere($orExpr);
129+
if ($orExpr->count() > 0) {
130+
$this->qb->andWhere($orExpr);
131+
}
130132

131133
if ($requestData["sort"]) {
132134
$column = $this->columnBuilder->getColumnByField($requestData["sort"]);

src/Resources/public/bootstrap-table.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/views/table/hello_bootstrap_table.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{% endif %}
2222

2323
<table
24-
data-classes="table table-striped table-sm"
24+
data-classes="{{ table.tableOptions.tableClassNames }}"
2525
class="hello-bootstrap-table"
2626
data-columns="{{ table.columns|json_encode }}"
2727
data-side-pagination="server"

0 commit comments

Comments
 (0)