|
6 | 6 | use Illuminate\Support\Collection; |
7 | 7 | use Yajra\DataTables\Contracts\DataTableScope; |
8 | 8 | use Yajra\DataTables\Contracts\DataTableButtons; |
| 9 | +use Yajra\DataTables\Html\Column; |
9 | 10 | use Yajra\DataTables\Transformers\DataArrayTransformer; |
10 | 11 |
|
11 | 12 | abstract class DataTable implements DataTableButtons |
@@ -238,7 +239,7 @@ protected function getDataForPrint() |
238 | 239 | */ |
239 | 240 | protected function printColumns() |
240 | 241 | { |
241 | | - return is_array($this->printColumns) ? $this->printColumns : $this->getPrintColumnsFromBuilder(); |
| 242 | + return is_array($this->printColumns) ? $this->toColumnsCollection($this->printColumns) : $this->getPrintColumnsFromBuilder(); |
242 | 243 | } |
243 | 244 |
|
244 | 245 | /** |
@@ -452,7 +453,30 @@ protected function getDataForExport() |
452 | 453 | */ |
453 | 454 | private function exportColumns() |
454 | 455 | { |
455 | | - return is_array($this->exportColumns) ? $this->exportColumns : $this->getExportColumnsFromBuilder(); |
| 456 | + return is_array($this->exportColumns) ? $this->toColumnsCollection($this->exportColumns) : $this->getExportColumnsFromBuilder(); |
| 457 | + } |
| 458 | + |
| 459 | + /** |
| 460 | + * Convert array to collection of Column class. |
| 461 | + * |
| 462 | + * @param array $columns |
| 463 | + * @return Collection |
| 464 | + */ |
| 465 | + private function toColumnsCollection(array $columns) { |
| 466 | + $collection = collect(); |
| 467 | + foreach ($columns as $column) { |
| 468 | + if (isset($column['data'])) { |
| 469 | + $column['title'] = $column['title'] ?? $column['data']; |
| 470 | + $collection->push(new Column($column)); |
| 471 | + } else { |
| 472 | + $data = []; |
| 473 | + $data['data'] = $column; |
| 474 | + $data['title'] = $column; |
| 475 | + $collection->push(new Column($data)); |
| 476 | + } |
| 477 | + } |
| 478 | + |
| 479 | + return $collection; |
456 | 480 | } |
457 | 481 |
|
458 | 482 | /** |
|
0 commit comments