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

Commit

Permalink
Ability to make a column optional (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
coclav authored Aug 9, 2021
1 parent b224061 commit 0c62ed7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ Inertia::render('Page/Index')->table(function ($table) {
});
```

The `addColumn` method has an optional third parameter to disable the column by default:

```php
$table->addColumn('name', 'Name', false);
```

#### Disable global search

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.
Expand Down
7 changes: 4 additions & 3 deletions php/InertiaTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,15 @@ public function applyTo(Response $response): Response
*
* @param string $key
* @param string $label
* @param bool $enabled
* @return self
*/
public function addColumn(string $key, string $label): self
public function addColumn(string $key, string $label, bool $enabled = true): self
{
$this->columns->put($key, [
'key' => $key,
'label' => $label,
'enabled' => true,
'enabled' => $enabled,
]);

return $this;
Expand All @@ -177,7 +178,7 @@ public function addColumn(string $key, string $label): self
public function addColumns(array $columns = []): self
{
foreach ($columns as $key => $value) {
$this->addColumn($key, $value);
$this->addColumn($key, $value, true);
}

return $this;
Expand Down
19 changes: 19 additions & 0 deletions tests/InertiaTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ public function it_can_add_a_column_to_toggle()
], $props);
}

/** @test */
public function it_can_add_a_column_that_is_disabled_by_default()
{
$table = new InertiaTable($this->request());
$table->addColumn('name', 'Name', false);

$props = $table->getQueryBuilderProps();

Assert::assertArraySubset([
"columns" => [
"name" => [
"key" => "name",
"label" => "Name",
"enabled" => false,
],
],
], $props);
}

/** @test */
public function it_gets_the_default_toggled_columns_from_the_query_String()
{
Expand Down

0 comments on commit 0c62ed7

Please sign in to comment.