@@ -83,6 +83,13 @@ class Column
8383 */
8484 protected $ relationColumn ;
8585
86+ /**
87+ * Original grid data.
88+ *
89+ * @var array
90+ */
91+ protected static $ originalGridData = [];
92+
8693 /**
8794 * @param string $name
8895 * @param string $label
@@ -331,7 +338,7 @@ public function editable()
331338 */
332339 public function value (Closure $ callable )
333340 {
334- $ this ->valueCallback = $ callable-> bindTo ( $ this ) ;
341+ $ this ->valueCallback = $ callable ;
335342
336343 return $ this ;
337344 }
@@ -410,27 +417,58 @@ protected function htmlWrap($value, $row = [])
410417 */
411418 public function fill (array $ data )
412419 {
413- foreach ($ data as &$ item ) {
414- $ this ->original = $ value = array_get ($ item , $ this ->name );
420+ foreach ($ data as $ key => &$ row ) {
421+ $ this ->original = $ value = array_get ($ row , $ this ->name );
422+
423+ $ isCustomColumn = !array_has ($ row , $ this ->name );
415424
416425 $ value = $ this ->htmlEntityEncode ($ value );
417426
418- array_set ($ item , $ this ->name , $ value );
427+ array_set ($ row , $ this ->name , $ value );
419428
420429 if ($ this ->hasValueCallback ()) {
421- $ value = call_user_func ($ this ->valueCallback , $ this ->original );
422- array_set ($ item , $ this ->name , $ value );
430+
431+ $ input = $ isCustomColumn ? $ row : $ this ->original ;
432+
433+ $ callback = $ this ->bindOriginalRow ($ this ->valueCallback , $ key );
434+ $ value = call_user_func ($ callback , $ input );
435+ array_set ($ row , $ this ->name , $ value );
423436 }
424437
425438 if ($ this ->hasHtmlCallback ()) {
426- $ value = $ this ->htmlWrap ($ value , $ item );
427- array_set ($ item , $ this ->name , $ value );
439+ $ value = $ this ->htmlWrap ($ value , $ row );
440+ array_set ($ row , $ this ->name , $ value );
428441 }
429442 }
430443
431444 return $ data ;
432445 }
433446
447+ /**
448+ * Set original grid data to column.
449+ *
450+ * @param Closure $callback
451+ * @param int $key
452+ *
453+ * @return Closure
454+ */
455+ protected function bindOriginalRow (Closure $ callback , $ key )
456+ {
457+ $ originalRow = static ::$ originalGridData [$ key ];
458+
459+ return $ callback ->bindTo ((object )$ originalRow );
460+ }
461+
462+ /**
463+ * Set original data for column.
464+ *
465+ * @param array $input
466+ */
467+ public static function setOriginalGridData (array $ input )
468+ {
469+ static ::$ originalGridData = $ input ;
470+ }
471+
434472 /**
435473 * Convert characters to HTML entities recursively.
436474 *
0 commit comments