[英]Sonata Admin List View, make more headers sort buttons?
I have an Admin class which has this definition of listFields: 我有一个Admin类,它有listFields的这个定义:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('type')
->add('created_at', 'datetime')
->add('updated_at', 'datetime')
->add('created_by')
->add('updated_by')
->add('is_active')
->add('is_deleted')
->add('_action', 'actions',
array(
'actions' => array(
'view' => array(),
'edit' => array(),
'delete' => array()
)
))
;
}
Only the "type" column is sortable - IE, when you hover over the table header for "Type" you see an asc/desc arrow and can click to re-order the rows based on this column. 只有“类型”列是可排序的 - IE,当您将鼠标悬停在“类型”的表头上时,您会看到一个asc / desc箭头,并且可以单击以根据此列重新排序行。
How do I get that to show up on more columns? 如何让它显示在更多列上?
I tried adding sortable=true but then it's trying to join to another Entity. 我尝试添加sortable = true但是它正在尝试加入另一个实体。
# we can sort the related entity properties like. This following condition site is an entity
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('name')
->add('site',null,array(
'sortable'=>true,
'sort_field_mapping'=> array('fieldName'=>'name'),
'sort_parent_association_mappings' => array(array('fieldName'=>'site')
)))
;
}
this is the way to sort the related entities in list configuration. 这是在列表配置中对相关实体进行排序的方法。 Just check this Sort list by an entity field
只需按实体字段检查此排序列表即可
Sonata will be able to sort a field if it knows what type it is ; 如果它知道它是什么类型,Sonata将能够对一个字段进行排序; if you list a related entity, it will be impossible to sort.
如果列出相关实体,则无法进行排序。
Here is the configureListFields() from an entity "Event" which has a title and is linked to another entity "City" . 这是来自实体“Event”的configureListFields() ,它具有标题并链接到另一个实体“City” 。
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('title')
->add('city')
}
A link will be created to the city but it will not be sortable, instead adding a specific field from "City" will work : 将为城市创建一个链接,但它不可排序,而是从“城市”添加特定字段将起作用:
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('title')
->add('city.name')
}
Now it's sortable. 现在可以排序了。
You have to add sortable
option on the field. 您必须在该字段上添加
sortable
选项。
Here is the code i use: 这是我使用的代码:
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->addIdentifier('name')
->add('application', null, array('sortable' => true))
->add('isActive', null, array('editable' => true))
->add('_action', 'actions', array(
'actions' => array(
'view' => array(),
'edit' => array(),
'delete' => array(),
)
))
;
}
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.