Skip to content

Commit 52b7370

Browse files
authored
[4.0] Add support for search panes extension. (#137)
* WIP: Add support for search panes extension. Fix yajra/laravel-datatables#2463 * Add threshold and viewTotal setter. * Support search panes on column builder. * Add more search pane options. * Add search pane name. * Orthogonal option setter. * Add Column Definition classes. * Allow callback value for searchPane. * Add hideTotal api.
1 parent fefbf5b commit 52b7370

File tree

7 files changed

+422
-3
lines changed

7 files changed

+422
-3
lines changed

src/Html/Column.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
77
use Illuminate\Support\Fluent;
8+
use Yajra\DataTables\Html\Options\Plugins\SearchPanes;
89

910
/**
1011
* @property string data
@@ -19,6 +20,8 @@
1920
*/
2021
class Column extends Fluent
2122
{
23+
use SearchPanes;
24+
2225
/**
2326
* @param array $attributes
2427
*/
@@ -101,7 +104,7 @@ public function orderable(bool $flag = true)
101104

102105
return $this;
103106
}
104-
107+
105108
/**
106109
* Set column responsive priority.
107110
*

src/Html/ColumnDefinition.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html;
4+
5+
use Illuminate\Support\Fluent;
6+
7+
class ColumnDefinition extends Fluent
8+
{
9+
use HasOptions;
10+
11+
public function targets($value)
12+
{
13+
$this->attributes['targets'] = (array) $value;
14+
15+
return $this;
16+
}
17+
}

src/Html/ColumnDefinitions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html;
4+
5+
use Illuminate\Support\Collection;
6+
7+
class ColumnDefinitions extends Collection
8+
{
9+
10+
}

src/Html/HasOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ trait HasOptions
2727
use Options\Plugins\RowReorder;
2828
use Options\Plugins\Scroller;
2929
use Options\Plugins\Select;
30+
use Options\Plugins\SearchPanes;
3031

3132
/**
3233
* Set deferLoading option value.

src/Html/Options/HasColumns.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Collection;
66
use Illuminate\Support\Str;
77
use Yajra\DataTables\Html\Column;
8+
use Illuminate\Contracts\Support\Arrayable;
89

910
/**
1011
* DataTables - Columns option builder.
@@ -16,17 +17,47 @@ trait HasColumns
1617
/**
1718
* Set columnDefs option value.
1819
*
19-
* @param array $value
20+
* @param mixed $value
2021
* @return $this
2122
* @see https://datatables.net/reference/option/columnDefs
2223
*/
23-
public function columnDefs(array $value)
24+
public function columnDefs($value)
2425
{
26+
if (is_callable($value)) {
27+
$value = app()->call($value);
28+
}
29+
30+
if ($value instanceof Arrayable) {
31+
$value = $value->toArray();
32+
}
33+
2534
$this->attributes['columnDefs'] = $value;
2635

2736
return $this;
2837
}
2938

39+
/**
40+
* Add a columnDef option.
41+
*
42+
* @param mixed $value
43+
* @return $this
44+
* @see https://datatables.net/reference/option/columnDefs
45+
*/
46+
public function addColumnDef($value)
47+
{
48+
if (is_callable($value)) {
49+
$value = app()->call($value);
50+
}
51+
52+
if ($value instanceof Arrayable) {
53+
$value = $value->toArray();
54+
}
55+
56+
$this->attributes['columnDefs'][] = $value;
57+
58+
return $this;
59+
}
60+
3061
/**
3162
* Set columns option value.
3263
*
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html\Options\Plugins;
4+
5+
use Yajra\DataTables\Html\SearchPane;
6+
use Illuminate\Contracts\Support\Arrayable;
7+
8+
/**
9+
* DataTables - Search panes plugin option builder.
10+
*
11+
* @see https://datatables.net/extensions/searchpanes
12+
* @see https://datatables.net/reference/option/searchPanes
13+
*/
14+
trait SearchPanes
15+
{
16+
/**
17+
* Set searchPane option value.
18+
*
19+
* @param bool|array $value
20+
* @return $this
21+
* @see https://datatables.net/reference/option/searchPanes
22+
*/
23+
public function searchPanes($value = true)
24+
{
25+
if (is_callable($value)) {
26+
$value = app()->call($value);
27+
}
28+
29+
if ($value instanceof Arrayable) {
30+
$value = $value->toArray();
31+
}
32+
33+
if (is_bool($value)) {
34+
$value = SearchPane::make()->show($value)->toArray();
35+
}
36+
37+
$this->attributes['searchPanes'] = $value;
38+
39+
return $this;
40+
}
41+
}

0 commit comments

Comments
 (0)