Skip to content

Commit b0fbba3

Browse files
committed
Strip html tags on title.
1 parent 6e12133 commit b0fbba3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Yajra\DataTables\Jobs;
44

5+
use Box\Spout\Common\Helper\CellTypeHelper;
56
use Box\Spout\Common\Type;
67
use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
78
use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
@@ -73,15 +74,19 @@ public function handle()
7374
$writer->openToFile(storage_path('app/exports/' . $this->batchId . '.' . $type));
7475

7576
$columns = $oTable->html()->getColumns()->filter->exportable;
76-
$writer->addRow(WriterEntityFactory::createRowFromArray($columns->pluck('title')->toArray()));
77+
$writer->addRow(
78+
WriterEntityFactory::createRowFromArray(
79+
$columns->map(fn($column) => strip_tags($column['title']))->toArray()
80+
)
81+
);
7782

7883
foreach ($dataTable->getFilteredQuery()->cursor() as $row) {
7984
$cells = collect();
8085
$columns->map(function (Column $column, $index) use ($row, $cells) {
8186
$property = $column['data'];
8287
$value = $row->{$property} ?? '';
8388

84-
if ($value instanceof \DateTime || $this->wantsDateFormat($column)) {
89+
if (CellTypeHelper::isDateTimeOrDateInterval($value) || $this->wantsDateFormat($column)) {
8590
$date = $value ? Date::dateTimeToExcel(Carbon::parse($value)) : '';
8691
$defaultDateFormat = config('datatables-export.default_date_format', 'yyyy-mm-dd');
8792
$format = $column['exportFormat'] ?? $defaultDateFormat;

0 commit comments

Comments
 (0)