Parcourir la source

Display column as boolean , `✓` for true, and `✗` for false.

很多业务中需要这个 `✓` 和 `✗` 来展示用户状态。业务状态
yalks il y a 5 ans
Parent
commit
dc01f0f220
1 fichiers modifiés avec 18 ajouts et 0 suppressions
  1. 18 0
      src/Grid/Column.php

+ 18 - 0
src/Grid/Column.php

@@ -756,6 +756,24 @@ class Column
 
         return implode(' ', $attrArr);
     }
+    
+    /**
+     * Display column as boolean , `✓` for true, and `✗` for false.
+     *
+     * @param array $map
+     * @param bool  $default
+     *
+     * @return $this
+     */
+    public function bool(array $map = [], $default = false)
+    {
+        return $this->display(function ($value) use ($map, $default) {
+            $bool = empty($map) ? boolval($value) : Arr::get($map, $value, $default);
+
+            return $bool ? '<i class="fa fa-check text-green"></i>' : '<i class="fa fa-close text-red"></i>';
+        });
+    }
+
 
     /**
      * Passes through all unknown calls to builtin displayer or supported displayer.