Skip to content

Commit 1480f56

Browse files
committed
Fix rowGroup plugin with tests
1 parent d929fff commit 1480f56

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

src/Html/Options/Plugins/RowGroup.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,33 @@
1212
trait RowGroup
1313
{
1414
/**
15-
* Set rowGroup option value.
15+
* Set rowGroup className option value.
1616
*
17-
* @param bool|array $value
17+
* @param string $value
1818
* @return $this
19-
* @see https://datatables.net/reference/option/rowGroup
19+
* @see https://datatables.net/reference/option/rowGroup.className
2020
*/
21-
public function rowGroup(bool|array $value = true): static
21+
public function rowGroupUpdate(string $value = 'group'): static
2222
{
23-
$this->attributes['rowGroup'] = $value;
24-
25-
return $this;
23+
return $this->rowGroup(['className' => $value]);
2624
}
2725

2826
/**
29-
* Set rowGroup className option value.
27+
* Set rowGroup option value.
3028
*
31-
* @param string $value
29+
* @param bool|array $value
3230
* @return $this
33-
* @see https://datatables.net/reference/option/rowGroup.className
31+
* @see https://datatables.net/reference/option/rowGroup
3432
*/
35-
public function rowGroupUpdate(string $value = 'group'): static
33+
public function rowGroup(bool|array $value = true): static
3634
{
37-
return $this->rowGroup(['className' => $value]);
35+
if (is_array($value)) {
36+
$this->attributes['rowGroup'] = array_merge((array) $this->attributes['rowGroup'], $value);
37+
} else {
38+
$this->attributes['rowGroup'] = $value;
39+
}
40+
41+
return $this;
3842
}
3943

4044
/**
@@ -120,4 +124,17 @@ public function rowGroupStartRender(string $value = null): static
120124
{
121125
return $this->rowGroup(['startRender' => $value]);
122126
}
127+
128+
/**
129+
* @param string|null $key
130+
* @return mixed
131+
*/
132+
public function getRowGroup(string $key = null): mixed
133+
{
134+
if (is_null($key)) {
135+
return $this->attributes['rowGroup'] ?? true;
136+
}
137+
138+
return $this->attributes['rowGroup'][$key] ?? false;
139+
}
123140
}

tests/BuilderOptionsPluginsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,32 @@ public function it_has_responsive_plugin()
180180
$this->assertEquals('type', $builder->getResponsive('details')['type']);
181181
$this->assertEquals('orthogonal', $builder->getResponsive('orthogonal'));
182182
}
183+
184+
/** @test */
185+
public function it_has_row_group_plugin()
186+
{
187+
$builder = $this->getHtmlBuilder();
188+
$builder->rowGroup();
189+
190+
$this->assertTrue($builder->getAttribute('rowGroup'));
191+
$this->assertTrue($builder->getRowGroup());
192+
193+
$builder->rowGroupDataSrc([1])
194+
->rowGroupEmptyDataGroup()
195+
->rowGroupEnable()
196+
->rowGroupEndClassName()
197+
->rowGroupEndRender('fn')
198+
->rowGroupStartClassName()
199+
->rowGroupStartRender();
200+
201+
$this->assertEquals([1], $builder->getRowGroup('dataSrc'));
202+
$this->assertEquals('No Group', $builder->getRowGroup('emptyDataGroup'));
203+
$this->assertEquals(true, $builder->getRowGroup('enable'));
204+
$this->assertEquals('group-end', $builder->getRowGroup('endClassName'));
205+
$this->assertEquals('fn', $builder->getRowGroup('endRender'));
206+
$this->assertEquals('group-start', $builder->getRowGroup('startClassName'));
207+
$this->assertEquals(null, $builder->getRowGroup('startRender'));
208+
}
209+
210+
183211
}

0 commit comments

Comments
 (0)