add value to filter
This commit is contained in:
parent
4a15305505
commit
f20f408f12
@ -22,7 +22,8 @@ $table->columns([
|
||||
"style" => ["width" => "300px"],
|
||||
"filter" => [
|
||||
'class' => InputFilter::class,
|
||||
'param' => 'text'
|
||||
'param' => 'text',
|
||||
'value' => 'value'
|
||||
],
|
||||
"value" => function ($cell) {
|
||||
return "<span style='color: sienna'>$cell</span>";
|
||||
@ -32,14 +33,16 @@ $table->columns([
|
||||
"format" => "html",
|
||||
"filter" => [
|
||||
'class' => SelectFilter::class,
|
||||
'param' => ['black', 'red', 'green', 'blue', 'yellow']
|
||||
'param' => ['black', 'red', 'green', 'blue', 'yellow'],
|
||||
'value' => 'red'
|
||||
],
|
||||
],
|
||||
'status' => [
|
||||
"format" => "integer",
|
||||
"filter" => [
|
||||
'class' => SelectFilter::class,
|
||||
'param' => getStatusLabel()
|
||||
'param' => getStatusLabel(),
|
||||
'value' => 'Активный'
|
||||
],
|
||||
"value" => function ($cell) {
|
||||
return getStatusLabel()[$cell];
|
||||
|
@ -7,10 +7,12 @@ abstract class Filter
|
||||
public string $html = '';
|
||||
public string|array $param;
|
||||
public string $name;
|
||||
public string $value;
|
||||
public function __construct(array $source)
|
||||
{
|
||||
$this->param = $source['param'] ?? '';
|
||||
$this->name = $source['name'];
|
||||
$this->value = $source['value'] ?? '';
|
||||
}
|
||||
|
||||
abstract public function fetch();
|
||||
|
@ -9,6 +9,6 @@ class InputFilter extends Filter
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
return "<td><input type='$this->param' name='$this->name'></td>";
|
||||
return "<td><input type='$this->param' name='$this->name' value ='$this->value'></td>";
|
||||
}
|
||||
}
|
@ -11,9 +11,13 @@ class SelectFilter extends Filter
|
||||
{
|
||||
$this->html = "<td><select name='$this->name'>";
|
||||
foreach ($this->param as $value) {
|
||||
if ($value === $this->value) {
|
||||
$this->html .= "<option value='$value' selected>$value</option>";
|
||||
} else {
|
||||
$this->html .= "<option value='$value'>$value</option>";
|
||||
}
|
||||
$this->html .= "</select></td>";
|
||||
}
|
||||
$this->html .= "value='$this->value'</select></td>";
|
||||
return $this->html;
|
||||
}
|
||||
}
|
@ -286,7 +286,8 @@ class ListJsonTable extends JasonTable
|
||||
$filter = $this->getCurrentFilter($key);
|
||||
$class = new $filter['class']([
|
||||
'param' => $filter['param'],
|
||||
'name' => $key
|
||||
'name' => $key,
|
||||
'value' => $filter['value']
|
||||
]);
|
||||
$this->html .= $class->fetch();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user