Skip to content

Commit c453bcf

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ignore_getters
2 parents 1095874 + 6662926 commit c453bcf

File tree

5 files changed

+150
-58
lines changed

5 files changed

+150
-58
lines changed

CHANGELOG.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88

99
### [Unreleased]
1010

11+
### [v10.6.2] - 2023-07-15
12+
13+
- fix: #3010 - convert expressions to strings #3029
14+
15+
### [v10.6.1] - 2023-07-05
16+
17+
- fix: #3025 #3026
18+
- fix the error introduced in 10.4.4 as described in #3025.
19+
20+
### [v10.6.0] - 2023-06-29
21+
22+
- feat: Expose autoFilter setter to disable post filtering #2981
23+
24+
### [v10.5.0] - 2023-06-29
25+
26+
- feat: Prevent editColumn when column is not shown #3018
27+
1128
### [v10.4.4] - 2023-06-27
1229

1330
- feat: Optimize countQuery with complex select #3008
@@ -135,7 +152,11 @@
135152
- Drop support for `ApiResourceDataTable`
136153
- PHP8 syntax / method signature changed
137154

138-
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v10.4.4...10.x
155+
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v10.6.2...10.x
156+
[v10.6.2]: https://github.com/yajra/laravel-datatables/compare/v10.6.2...v10.6.1
157+
[v10.6.1]: https://github.com/yajra/laravel-datatables/compare/v10.6.1...v10.6.0
158+
[v10.6.0]: https://github.com/yajra/laravel-datatables/compare/v10.6.0...v10.5.0
159+
[v10.5.0]: https://github.com/yajra/laravel-datatables/compare/v10.5.0...v10.4.4
139160
[v10.4.4]: https://github.com/yajra/laravel-datatables/compare/v10.4.4...v10.4.3
140161
[v10.3.1]: https://github.com/yajra/laravel-datatables/compare/v10.3.1...v10.3.0
141162
[v10.3.1]: https://github.com/yajra/laravel-datatables/compare/v10.3.1...v10.3.0

src/DataTableAbstract.php

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ abstract class DataTableAbstract implements DataTable
104104
* @var array
105105
*/
106106
protected array $templates = [
107-
'DT_RowId' => '',
107+
'DT_RowId' => '',
108108
'DT_RowClass' => '',
109-
'DT_RowData' => [],
110-
'DT_RowAttr' => [],
109+
'DT_RowData' => [],
110+
'DT_RowAttr' => [],
111111
];
112112

113113
/**
@@ -148,6 +148,8 @@ abstract class DataTableAbstract implements DataTable
148148

149149
protected mixed $transformer;
150150

151+
protected bool $editOnlySelectedColumns = false;
152+
151153
/**
152154
* Can the DataTable engine be created with these parameters.
153155
*
@@ -245,7 +247,13 @@ public function ignoreGetters(): static
245247
*/
246248
public function editColumn($name, $content): static
247249
{
248-
$this->columnDef['edit'][] = ['name' => $name, 'content' => $content];
250+
if ($this->editOnlySelectedColumns) {
251+
if (! count($this->request->columns()) || in_array($name, Arr::pluck($this->request->columns(), 'name'))) {
252+
$this->columnDef['edit'][] = ['name' => $name, 'content' => $content];
253+
}
254+
} else {
255+
$this->columnDef['edit'][] = ['name' => $name, 'content' => $content];
256+
}
249257

250258
return $this;
251259
}
@@ -598,6 +606,18 @@ public function skipPaging(): static
598606
return $this;
599607
}
600608

609+
/**
610+
* Skip auto filtering as needed.
611+
*
612+
* @return $this
613+
*/
614+
public function skipAutoFilter(): static
615+
{
616+
$this->autoFilter = false;
617+
618+
return $this;
619+
}
620+
601621
/**
602622
* Push a new column name to blacklist.
603623
*
@@ -881,10 +901,10 @@ protected function processResults($results, $object = false): array
881901
protected function render(array $data): JsonResponse
882902
{
883903
$output = $this->attachAppends([
884-
'draw' => $this->request->draw(),
885-
'recordsTotal' => $this->totalRecords,
904+
'draw' => $this->request->draw(),
905+
'recordsTotal' => $this->totalRecords,
886906
'recordsFiltered' => $this->filteredRecords ?? 0,
887-
'data' => $data,
907+
'data' => $data,
888908
]);
889909

890910
if ($this->config->isDebugging()) {
@@ -948,11 +968,11 @@ protected function errorResponse(\Exception $exception)
948968
$this->getLogger()->error($exception);
949969

950970
return new JsonResponse([
951-
'draw' => $this->request->draw(),
952-
'recordsTotal' => $this->totalRecords,
971+
'draw' => $this->request->draw(),
972+
'recordsTotal' => $this->totalRecords,
953973
'recordsFiltered' => 0,
954-
'data' => [],
955-
'error' => $error ? __($error) : "Exception Message:\n\n".$exception->getMessage(),
974+
'data' => [],
975+
'error' => $error ? __($error) : "Exception Message:\n\n".$exception->getMessage(),
956976
]);
957977
}
958978

@@ -1053,4 +1073,11 @@ protected function getPrimaryKeyName(): string
10531073
{
10541074
return 'id';
10551075
}
1076+
1077+
public function editOnlySelectedColumns(): static
1078+
{
1079+
$this->editOnlySelectedColumns = true;
1080+
1081+
return $this;
1082+
}
10561083
}

src/QueryDataTable.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function prepareCountQuery(): QueryBuilder
164164
$builder = clone $this->query;
165165

166166
if ($this->isComplexQuery($builder)) {
167-
$builder->select(DB::raw('1'));
167+
$builder->select(DB::raw('1 as dt_row_count'));
168168
if ($this->ignoreSelectInCountQuery || ! $this->isComplexQuery($builder)) {
169169
return $this->getConnection()
170170
->query()
@@ -311,6 +311,19 @@ protected function getColumnSearchKeyword(int $i, bool $raw = false): string
311311
return $this->setupKeyword($keyword);
312312
}
313313

314+
protected function getColumnNameByIndex(int $index): string
315+
{
316+
$name = (isset($this->columns[$index]) && $this->columns[$index] != '*')
317+
? $this->columns[$index]
318+
: $this->getPrimaryKeyName();
319+
320+
if ($name instanceof Expression) {
321+
$name = $name->getValue($this->query->getGrammar());
322+
}
323+
324+
return in_array($name, $this->extraColumns, true) ? $this->getPrimaryKeyName() : $name;
325+
}
326+
314327
/**
315328
* Apply filterColumn api search.
316329
*

0 commit comments

Comments
 (0)