![](/img/trans.png)
[英]Include 'NULL' values in filter along with range filter in Elastica
[英]Include null values in Sonata boolean filter
final class SomeAdmin extends AbstractAdmin
{
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('sending_error', null, [
'label' => 'some label;',
]);
}
}
// ...
class Entity
{
/**
* @var bool|null
*
* @ORM\Column(type="boolean", nullable=true)
*/
private $sending_error;
// ...
}
此代碼生成具有兩個值的過濾器:是/否。 “yes”選項將在字段中返回值為“true”的行,過濾器的“false”選項將在db字段中返回值為“false”的行,但如何在“no”過濾器選項中包含值為“null”的行?
如果您在 add() 選項中設置它們,您可以為過濾器添加自定義選項。
對於 4.3 之前的 symfony 版本和 sonata-admin-bundle 3,您可以這樣做:
$datagridMapper
->add('sending_error',
'doctrine_orm_string',
array(),
'choice',
array('choices' => array('m' => 'Male', 'f' => 'Female')
)
);
對於最新版本(我已經在本地測試並為我工作)
->add('sending_error', null, ['label' => 'some label'], ChoiceType::class, [
'choices' => ['True' => True, 'False' =>False,'Empty'=>null]])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.