Skip to content

Commit b01b698

Browse files
committed
Fix options to work on re-render
1 parent 3d39eb8 commit b01b698

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1212

1313
- Config file to choose frontend framework - currently limited to bootstrap
1414
- Render method to columns which returns whatever you put into it, you can return a view, html, an attribute, etc.
15-
- Pulled in and modified the HTML component library from laravelcollective so you an return html components from the render method. i.e.: $this->image(...);
15+
- Pulled in and modified the HTML component library from laravelcollective so you can return html components from the render method. i.e.: $this->image(...);
1616
- Added new loading config on whether to keep displaying the current data while loading or collapse it
17-
- Added ability to set frontend framework specific options via the mount method on a per component basis.
17+
- Added ability to set frontend framework specific options via a property on a per component basis.
1818

1919
### Changed
2020

README.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,27 +288,24 @@ public function html($html): HtmlString
288288

289289
There are some frontend framework specific options that can be set.
290290

291-
These have to be set from the `mount()` method of your component.
291+
These have to be set from the `$options` property of your component.
292292

293293
They are done this way instead of the config file that way you can have per-component control over these settings.
294294

295295
```php
296-
public function mount()
297-
{
298-
$this->setOptions([
299-
// The class set on the table when using bootstrap
300-
'bootstrap.classes.table' => 'table table-striped table-bordered',
301-
302-
// Whether or not the table is wrapped in a `.container-fluid` or not
303-
'bootstrap.container' => true,
296+
protected $options = [
297+
// The class set on the table when using bootstrap
298+
'bootstrap.classes.table' => 'table table-striped table-bordered',
304299

305-
// Whether or not the table is wrapped in a `.table-responsive` or not
306-
'bootstrap.responsive' => true,
307-
]);
308-
}
300+
// Whether or not the table is wrapped in a `.container-fluid` or not
301+
'bootstrap.container' => true,
302+
303+
// Whether or not the table is wrapped in a `.table-responsive` or not
304+
'bootstrap.responsive' => true,
305+
];
309306
```
310307

311-
For this to work you have to pass an associative array of overrides to the `setOptions()` method. The above are the defaults, if you're not changing them then you can leave them out.
308+
For this to work you have to pass an associative array of overrides to the `$options` property. The above are the defaults, if you're not changing them then you can leave them out or disregard the property all together.
312309

313310
### Passing Properties
314311

src/TableComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($id = null)
6464
$this->paginationTheme = 'bootstrap';
6565
}
6666

67-
$this->setOptions();
67+
$this->setOptions($this->options);
6868

6969
parent::__construct($id);
7070
}

src/Traits/Options.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
*/
1010
trait Options
1111
{
12+
13+
/**
14+
* @var array
15+
*/
16+
protected $options = [];
17+
1218
/**
1319
* @var array
1420
*/
15-
protected $options = [
21+
protected $optionDefaults = [
1622
'bootstrap' => [
1723
'classes' => [
1824
'table' => 'table table-bordered table-striped',
@@ -29,7 +35,7 @@ trait Options
2935
*/
3036
public function getOption($option)
3137
{
32-
return Arr::dot($this->options)[$option] ?? null;
38+
return Arr::dot($this->optionDefaults)[$option] ?? null;
3339
}
3440

3541
/**
@@ -38,7 +44,7 @@ public function getOption($option)
3844
protected function setOptions(array $overrides = []): void
3945
{
4046
foreach ($overrides as $key => $value) {
41-
data_set($this->options, $key, $value);
47+
data_set($this->optionDefaults, $key, $value);
4248
}
4349
}
4450
}

0 commit comments

Comments
 (0)