Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit 0c62ed7

Browse files
authored
Ability to make a column optional (#30)
1 parent b224061 commit 0c62ed7

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Diff for: README.md

+6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ Inertia::render('Page/Index')->table(function ($table) {
101101
});
102102
```
103103

104+
The `addColumn` method has an optional third parameter to disable the column by default:
105+
106+
```php
107+
$table->addColumn('name', 'Name', false);
108+
```
109+
104110
#### Disable global search
105111

106112
By default, global search is enabled. This query will be applied to the filters by the `global` attribute. If you don't want to use the global search, you can use the `disableGlobalSearch` method.

Diff for: php/InertiaTable.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,15 @@ public function applyTo(Response $response): Response
161161
*
162162
* @param string $key
163163
* @param string $label
164+
* @param bool $enabled
164165
* @return self
165166
*/
166-
public function addColumn(string $key, string $label): self
167+
public function addColumn(string $key, string $label, bool $enabled = true): self
167168
{
168169
$this->columns->put($key, [
169170
'key' => $key,
170171
'label' => $label,
171-
'enabled' => true,
172+
'enabled' => $enabled,
172173
]);
173174

174175
return $this;
@@ -177,7 +178,7 @@ public function addColumn(string $key, string $label): self
177178
public function addColumns(array $columns = []): self
178179
{
179180
foreach ($columns as $key => $value) {
180-
$this->addColumn($key, $value);
181+
$this->addColumn($key, $value, true);
181182
}
182183

183184
return $this;

Diff for: tests/InertiaTableTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ public function it_can_add_a_column_to_toggle()
4747
], $props);
4848
}
4949

50+
/** @test */
51+
public function it_can_add_a_column_that_is_disabled_by_default()
52+
{
53+
$table = new InertiaTable($this->request());
54+
$table->addColumn('name', 'Name', false);
55+
56+
$props = $table->getQueryBuilderProps();
57+
58+
Assert::assertArraySubset([
59+
"columns" => [
60+
"name" => [
61+
"key" => "name",
62+
"label" => "Name",
63+
"enabled" => false,
64+
],
65+
],
66+
], $props);
67+
}
68+
5069
/** @test */
5170
public function it_gets_the_default_toggled_columns_from_the_query_String()
5271
{

0 commit comments

Comments
 (0)