|
@@ -4,6 +4,7 @@ namespace Dcat\Admin\Grid\Column;
|
|
|
|
|
|
use Dcat\Admin\Grid\Column;
|
|
|
use Dcat\Admin\Grid\Displayers\AbstractDisplayer;
|
|
|
+use Dcat\Admin\Support\Helper;
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
use Illuminate\Support\Arr;
|
|
|
use Illuminate\Support\Collection;
|
|
@@ -182,7 +183,7 @@ trait HasDisplayers
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Limit the number of characters in a string.
|
|
|
+ * Limit the number of characters in a string, or the number of element in a array.
|
|
|
*
|
|
|
* @param int $limit
|
|
|
* @param string $end
|
|
@@ -192,6 +193,20 @@ trait HasDisplayers
|
|
|
public function limit($limit = 100, $end = '...')
|
|
|
{
|
|
|
return $this->display(function ($value) use ($limit, $end) {
|
|
|
+ if ($value !== null && ! is_scalar($value)) {
|
|
|
+ $value = Helper::array($value);
|
|
|
+
|
|
|
+ if (count($value) <= $limit) {
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $value = array_slice($value, 0, $limit);
|
|
|
+
|
|
|
+ array_push($value, $end);
|
|
|
+
|
|
|
+ return $value;
|
|
|
+ }
|
|
|
+
|
|
|
if (mb_strlen($value, 'UTF-8') <= $limit) {
|
|
|
return $value;
|
|
|
}
|