Skip to content

Commit b03e64c

Browse files
Merge pull request #2198 from VikassWebkul214254/email-and-contact-columns-of-exported-file
issue #2172 fixed
2 parents bf03a46 + 8b7e273 commit b03e64c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/Webkul/DataGrid/src/Exports/DataGridExport.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,37 @@ public function headings(): array
3737
}
3838

3939
/**
40-
* Mapping.
40+
* Map each row for export.
4141
*/
4242
public function map(mixed $record): array
4343
{
4444
return collect($this->datagrid->getColumns())
4545
->filter(fn ($column) => $column->getExportable())
46-
->map(fn ($column) => $record->{$column->getIndex()})
46+
->map(function ($column) use ($record) {
47+
$index = $column->getIndex();
48+
$value = $record->{$index};
49+
50+
if (in_array($index, ['emails', 'contact_numbers']) && is_string($value)) {
51+
return $this->extractValuesFromJson($value);
52+
}
53+
54+
return $value;
55+
})
4756
->toArray();
4857
}
58+
59+
/**
60+
* Extract 'value' fields from a JSON string.
61+
*/
62+
protected function extractValuesFromJson(string $json): string
63+
{
64+
$decoded = json_decode($json, true);
65+
66+
if (json_last_error() === JSON_ERROR_NONE
67+
&& is_array($decoded)) {
68+
return collect($decoded)->pluck('value')->implode(', ');
69+
}
70+
71+
return $json;
72+
}
4973
}

0 commit comments

Comments
 (0)