diff --git a/src/Grid/Columns/DataColumn.php b/src/Grid/Columns/DataColumn.php index dc705fb..e1c2d13 100644 --- a/src/Grid/Columns/DataColumn.php +++ b/src/Grid/Columns/DataColumn.php @@ -11,6 +11,7 @@ class DataColumn extends AbstractColumn protected $attribute; protected $format = 'raw'; protected $sort = true; + protected $emptyValue = ''; /** * @param mixed $attribute @@ -54,6 +55,16 @@ protected function setFormat(string $format): void $this->format = strtolower($format); } + public function getEmptyValue() + { + return $this->emptyValue; + } + + protected function setEmptyValue($value): void + { + $this->emptyValue = $value; + } + protected function checkConfiguration() { if ((!is_string($this->attribute) || empty($this->attribute)) && $this->value === null) { @@ -86,9 +97,9 @@ public function getFilterContent() public function getCellContent($entity) { $result = (string)$this->getCellValue($entity); - return $this->format === 'html' - ? $result - : htmlspecialchars($result); + return empty($result) + ? $this->emptyValue + : ($this->format === 'html' ? $result : htmlspecialchars($result)); } protected function getCellValue($entity) diff --git a/src/Grid/Columns/DateColumn.php b/src/Grid/Columns/DateColumn.php index 0a0acc7..34c4377 100644 --- a/src/Grid/Columns/DateColumn.php +++ b/src/Grid/Columns/DateColumn.php @@ -18,7 +18,8 @@ public function getCellContent($entity) } elseif (is_string($value) && !empty($this->dateFormat)) { return date($this->dateFormat, strtotime($value)); } - return (string)$value; + $value = (string)$value; + return empty($value) ? $this->emptyValue : $value; } /** diff --git a/src/Grid/Columns/ImageColumn.php b/src/Grid/Columns/ImageColumn.php index 18c0fef..fceda20 100644 --- a/src/Grid/Columns/ImageColumn.php +++ b/src/Grid/Columns/ImageColumn.php @@ -17,7 +17,7 @@ class ImageColumn extends DataColumn protected $alt; - protected $noImageMessage = '-'; + protected $emptyValue = '-'; public function getCellContent($entity) { @@ -33,7 +33,7 @@ public function getCellContent($entity) } return htmlspecialchars($value); } else { - return $this->noImageMessage; + return $this->emptyValue; } } @@ -87,20 +87,4 @@ protected function setAlt(callable $alt): void { $this->alt = $alt; } - - /** - * @return string - */ - public function getNoImageMessage(): string - { - return $this->noImageMessage; - } - - /** - * @param string $noImageMessage - */ - protected function setNoImageMessage(string $noImageMessage): void - { - $this->noImageMessage = $noImageMessage; - } } diff --git a/src/Grid/Columns/RelationColumn.php b/src/Grid/Columns/RelationColumn.php index bddf4b6..61e64a7 100644 --- a/src/Grid/Columns/RelationColumn.php +++ b/src/Grid/Columns/RelationColumn.php @@ -37,7 +37,7 @@ public function getCellContent($entity) ? $result : htmlspecialchars($result); } - return is_string($obj) ? $obj : ''; + return is_string($obj) ? (empty($obj) ? $this->emptyValue : $obj) : $this->emptyValue; } /**