Skip to content

Commit 0c1984c

Browse files
resolve #1
1 parent fe0193f commit 0c1984c

File tree

1 file changed

+64
-24
lines changed

1 file changed

+64
-24
lines changed

README.md

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,17 @@ or add
2020
```
2121
to the require section of your `composer.json` file.
2222

23-
## Server-side processing
24-
25-
To enable server-side processing add `DataTableAction` to controller like this:
23+
## Basic Usage
2624

2725
```php
28-
class SomeController extends Controller
29-
{
30-
public function actions()
31-
{
32-
return [
33-
'datatables' => [
34-
'class' => 'nullref\datatable\DataTableAction',
35-
'query' => Model::find(),
36-
],
37-
];
38-
}
39-
40-
}
41-
```
42-
43-
In DataTable options specify:
44-
```js
45-
{
46-
"serverSide": true,
47-
"ajax": "/datatables"
48-
}
26+
<?= \nullref\datatable\DataTable::widget([
27+
'data' => $dataProvider->getModels(),
28+
'columns' => [
29+
'id',
30+
'name',
31+
'email'
32+
],
33+
]) ?>
4934
```
5035

5136
## Add Links to row
@@ -100,3 +85,58 @@ It's posible to use custom styles and scripts:
10085
'styling' => false,
10186
]
10287
```
88+
89+
## Server-side processing
90+
91+
To enable server-side processing add `DataTableAction` to controller like this:
92+
93+
```php
94+
class SomeController extends Controller
95+
{
96+
public function actions()
97+
{
98+
return [
99+
'datatables' => [
100+
'class' => 'nullref\datatable\DataTableAction',
101+
'query' => Model::find(),
102+
],
103+
];
104+
}
105+
106+
}
107+
```
108+
109+
Searching and ordering can be customized using closures
110+
```
111+
public function actions()
112+
{
113+
return [
114+
'datatables' => [
115+
'class' => 'nullref\datatable\DataTableAction',
116+
'query' => Model::find(),
117+
'applyOrder' => function($query, $columns, $order) {
118+
//custom ordering logic
119+
return $query;
120+
},
121+
'applyFilter' => function($query, $columns, $search) {
122+
//custom search logic
123+
return $query;
124+
},
125+
],
126+
];
127+
}
128+
129+
```
130+
131+
132+
In DataTable options specify:
133+
```js
134+
{
135+
"serverSide": true,
136+
"ajax": "/datatables"
137+
}
138+
```
139+
140+
141+
142+

0 commit comments

Comments
 (0)