Skip to content

Commit 2ffc4c0

Browse files
committed
Add addButton method
1 parent a698a51 commit 2ffc4c0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Html/Options/Plugins/Buttons.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Yajra\DataTables\Html\Options\Plugins;
44

55
use Illuminate\Contracts\Support\Arrayable;
6+
use Yajra\DataTables\Html\Button;
67

78
/**
89
* DataTables - Buttons plugin option builder.
@@ -34,6 +35,17 @@ public function buttons(...$buttons): static
3435
return $this;
3536
}
3637

38+
/**
39+
* @param \Yajra\DataTables\Html\Button $button
40+
* @return $this
41+
*/
42+
public function addButton(Button $button): static
43+
{
44+
$this->attributes['buttons'][] = $button->toArray();
45+
46+
return $this;
47+
}
48+
3749
/**
3850
* Get builder buttons.
3951
*

tests/BuilderOptionsPluginsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public function it_has_buttons_plugin()
5656
$this->assertCount(2, $builder->getButtons());
5757
$this->assertIsArray($builder->getButtons()[0]);
5858

59-
$builder->buttons([
60-
Button::make('remove'),
61-
]);
62-
59+
$builder->buttons([Button::make('remove')]);
6360
$this->assertCount(1, $builder->getButtons());
61+
62+
$builder->addButton(Button::make('edit'));
63+
$this->assertCount(2, $builder->getButtons());
6464
}
6565

6666
/** @test */

0 commit comments

Comments
 (0)