Skip to content

Commit aa607b6

Browse files
committed
Fix rowReorder plugin with tests
1 parent 1480f56 commit aa607b6

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

src/Html/Options/Plugins/RowReorder.php

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

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

4044
/**
@@ -108,4 +112,17 @@ public function rowReorderUpdate(bool $value = true): static
108112
{
109113
return $this->rowReorder(['update' => $value]);
110114
}
115+
116+
/**
117+
* @param string|null $key
118+
* @return mixed
119+
*/
120+
public function getRowReorder(string $key = null): mixed
121+
{
122+
if (is_null($key)) {
123+
return $this->attributes['rowReorder'] ?? true;
124+
}
125+
126+
return $this->attributes['rowReorder'][$key] ?? false;
127+
}
111128
}

tests/BuilderOptionsPluginsTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,33 @@ public function it_has_row_group_plugin()
207207
$this->assertEquals(null, $builder->getRowGroup('startRender'));
208208
}
209209

210+
/** @test */
211+
public function it_has_row_reorder_plugin()
212+
{
213+
$builder = $this->getHtmlBuilder();
214+
$builder->rowReorder();
215+
216+
$this->assertTrue($builder->getAttribute('rowReorder'));
217+
$this->assertTrue($builder->getRowReorder());
218+
219+
$builder->rowReorderDataSrc([1])
220+
->rowReorderEditor('editor')
221+
->rowReorderEnable()
222+
->rowReorderFormOptions(['main' => []])
223+
->rowReorderSelector()
224+
->rowReorderSnapX()
225+
->rowReorderUpdate();
226+
227+
$this->assertEquals([1], $builder->getRowReorder('dataSrc'));
228+
$this->assertEquals('editor', $builder->getRowReorder('editor'));
229+
$this->assertEquals(true, $builder->getRowReorder('enable'));
230+
$this->assertEquals(['main' => []], $builder->getRowReorder('formOptions'));
231+
$this->assertEquals('td:first-child', $builder->getRowReorder('selector'));
232+
$this->assertEquals(true, $builder->getRowReorder('snapX'));
233+
$this->assertEquals(true, $builder->getRowReorder('update'));
234+
235+
236+
}
237+
210238

211239
}

0 commit comments

Comments
 (0)