Skip to content

Commit 436589d

Browse files
add bulk identifier table option (#9)
1 parent 840e432 commit 436589d

File tree

8 files changed

+26
-4
lines changed

8 files changed

+26
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ All options that should not be provided directly as data-attributes of the table
671671
| -------------------------- | ------ | ------------------------------- |
672672
| tableClassNames | string | "table table-stripped table-sm" |
673673
| enableCheckbox | bool | false |
674+
| bulkIndentifier | string | "id" |
674675
| bulkUrl | string | "" |
675676
| bulkActionSelectClassNames | string | "form-control" |
676677
| bulkActions | array | [ ] |

assets/app.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,31 @@ $(function () {
6868
$tables.each(index => {
6969
const $table = $($tables[index]);
7070
const tableName = $table.data('id-table');
71+
const bulkIdentifier = $table.data('bulk-identifier');
7172

7273
$table.bootstrapTable('destroy').bootstrapTable({
7374
queryParams: function (params) {
7475
params.isCallback = true;
7576
params.tableName = tableName;
7677
return params;
78+
},
79+
icons: {
80+
advancedSearchIcon: 'fa-filter',
81+
paginationSwitchDown: 'fa-caret-square-o-down',
82+
paginationSwitchUp: 'fa-caret-square-o-up',
83+
columns: 'fa-columns',
84+
refresh: 'fa-sync',
85+
export: 'fa-download'
7786
}
7887
});
7988

8089
const $bulkForm = $("#bulk_form_" + tableName);
8190
$bulkForm.submit(function (e) {
8291
const selectedRows = $table.bootstrapTable("getSelections");
92+
const identifiers = selectedRows.map(row => row[bulkIdentifier]);
93+
8394
const hidden = $("#bulk_form_" + tableName + " input[type=hidden]");
84-
hidden.val(JSON.stringify(selectedRows));
95+
hidden.val(JSON.stringify(identifiers));
8596
});
8697
});
8798
}

src/Columns/BooleanColumn.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ protected function configureOutputOptions(OptionsResolver $resolver)
1515

1616
$resolver->setDefaults(array(
1717
"trueLabel" => "True",
18-
"falseLabel" => "False"
18+
"falseLabel" => "False",
19+
"filterControl" => "select"
1920
));
2021

2122
$resolver->setAllowedTypes('trueLabel', 'string');

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private function addTableOptions()
5555
->children()
5656
->scalarNode('tableClassNames')->end()
5757
->booleanNode('enableCheckbox')->end()
58+
->scalarNode('bulkIdentifier')->end()
5859
->scalarNode('bulkUrl')->end()
5960
->scalarNode('bulkActionSelectClassNames')->end()
6061
->scalarNode('bulkButtonName')->end()

src/HelloBootstrapTable.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ public function createView()
151151
$columns = $this->columnBuilder->buildColumnsArray();
152152

153153
if ($this->tableOptions['enableCheckbox']) {
154+
if (!$this->columnBuilder->getColumnByField($this->tableOptions['bulkIdentifier'])) {
155+
throw new \Exception("Field for bulk identifier not found in columns. Given identifier: " . $this->tableOptions['bulkIdentifier']);
156+
}
157+
154158
array_unshift($columns, array("checkbox" => true));
155159
}
156160

@@ -298,14 +302,17 @@ protected function configureTableOptions(OptionsResolver $resolver)
298302
$resolver->setDefaults(array(
299303
'tableClassNames' => 'table table-striped table-sm',
300304
'enableCheckbox' => false,
305+
'bulkIdentifier' => 'id',
301306
'bulkUrl' => '',
302307
'bulkActionSelectClassNames' => 'form-control',
303308
'bulkActions' => array(),
304309
'bulkButtonName' => 'Okay',
305310
'bulkButtonClassNames' => 'btn btn-primary'
306311
));
307312

313+
$resolver->setAllowedTypes("tableClassNames", ["string"]);
308314
$resolver->setAllowedTypes("enableCheckbox", ["bool"]);
315+
$resolver->setAllowedTypes("bulkIdentifier", ["string"]);
309316
$resolver->setAllowedTypes("bulkUrl", ["string"]);
310317
$resolver->setAllowedTypes("bulkActionSelectClassNames", ["string"]);
311318
$resolver->setAllowedTypes("bulkActions", ["array"]);

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
data-classes="{{ table.tableOptions.tableClassNames }}"
1010
data-columns="{{ table.columns|json_encode }}"
1111
data-url="{{ table.callbackUrl }}"
12+
data-bulk-identifier="{{ table.tableOptions.bulkIdentifier }}"
1213
{% for key, value in table.tableDataset %}
1314
data-{{ key }}="{{ value is iterable ? value|json_encode : value|raw }}"
1415
{% endfor %}

src/Twig/BootstrapTableTwigExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class BootstrapTableTwigExtension extends AbstractExtension
1515
{
16-
const ASSET_VERSION = "0.4.0";
16+
const ASSET_VERSION = "0.5.0";
1717

1818
/**
1919
* {@inheritdoc}

0 commit comments

Comments
 (0)