@@ -144,13 +144,9 @@ protected function filename()
144
144
*/
145
145
protected function getDataForExport ()
146
146
{
147
- return array_map (function ($ row ) {
148
- if ($ columns = $ this ->exportColumns ()) {
149
- return (new DataTransformer ())->transform ($ row , $ columns , 'exportable ' );
150
- }
147
+ $ columns = $ this ->exportColumns ();
151
148
152
- return $ row ;
153
- }, $ this ->getAjaxResponseData ());
149
+ return $ this ->mapResponseToColumns ($ columns , 'exportable ' );
154
150
}
155
151
156
152
/**
@@ -193,6 +189,24 @@ public function builder()
193
189
return $ this ->datatables ->getHtmlBuilder ();
194
190
}
195
191
192
+ /**
193
+ * Map ajax response to columns definition.
194
+ *
195
+ * @param mixed $columns
196
+ * @param string $type
197
+ * @return array
198
+ */
199
+ protected function mapResponseToColumns ($ columns , $ type )
200
+ {
201
+ return array_map (function ($ row ) use ($ columns , $ type ) {
202
+ if ($ columns ) {
203
+ return (new DataTransformer ())->transform ($ row , $ columns , $ type );
204
+ }
205
+
206
+ return $ row ;
207
+ }, $ this ->getAjaxResponseData ());
208
+ }
209
+
196
210
/**
197
211
* Get decorated data as defined in datatables ajax response.
198
212
*
@@ -248,13 +262,9 @@ public function printPreview()
248
262
*/
249
263
protected function getDataForPrint ()
250
264
{
251
- return array_map (function ($ row ) {
252
- if ($ columns = $ this ->printColumns ()) {
253
- return (new DataTransformer ())->transform ($ row , $ columns , 'printable ' );
254
- }
265
+ $ columns = $ this ->printColumns ();
255
266
256
- return $ row ;
257
- }, $ this ->getAjaxResponseData ());
267
+ return $ this ->mapResponseToColumns ($ columns , 'printable ' );
258
268
}
259
269
260
270
/**
0 commit comments