|
|
@@ -18,6 +18,10 @@ class SelectTable extends Field
|
|
|
|
|
|
protected $style = 'primary';
|
|
|
|
|
|
+ protected $visibleColumn;
|
|
|
+
|
|
|
+ protected $key;
|
|
|
+
|
|
|
public function __construct($column, $arguments = [])
|
|
|
{
|
|
|
parent::__construct($column, $arguments);
|
|
|
@@ -71,6 +75,22 @@ class SelectTable extends Field
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 设置选中的key以及标题字段.
|
|
|
+ *
|
|
|
+ * @param $visibleColumn
|
|
|
+ * @param $key
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function pluck(?string $visibleColumn, ?string $key = 'id')
|
|
|
+ {
|
|
|
+ $this->visibleColumn = $visibleColumn;
|
|
|
+ $this->key = $key;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param array $options
|
|
|
*
|
|
|
@@ -94,7 +114,7 @@ class SelectTable extends Field
|
|
|
*/
|
|
|
public function model(string $model, string $id = 'id', string $text = 'title')
|
|
|
{
|
|
|
- return $this->options(function ($v) use ($model, $id, $text) {
|
|
|
+ return $this->pluck($text, $id)->options(function ($v) use ($model, $id, $text) {
|
|
|
if (! $v) {
|
|
|
return [];
|
|
|
}
|
|
|
@@ -129,6 +149,14 @@ class SelectTable extends Field
|
|
|
$this->dialog
|
|
|
->footer($this->renderFooter())
|
|
|
->button($this->renderButton());
|
|
|
+
|
|
|
+ // 设置选中的字段和待显示的标题字段
|
|
|
+ $this->dialog
|
|
|
+ ->getTable()
|
|
|
+ ->getRenderable()
|
|
|
+ ->payload([
|
|
|
+ LazyRenderable::ROW_SELECTOR_COLUMN_NAME => [$this->key, $this->visibleColumn],
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
public function render()
|