我想在Sonata Admin中对包含IP地址(版本4)(其他包含IPv6)的列表进行排序。对它进行排序有什么变化吗?
当前排序:
正确的顺序:
单击标题时,行为应该是正确的。 IP-Sorting不是default-orderBy设置。
修改
我已经实现了一个(D2-)函数,它计算IP地址的INT值。
db2 "select INET_ATON (device_ip_v4) from devices order by INET_ATON (device_ip_v4)";
1
--------------------
16843009
16843009
16843009
2887254017
设备的实体:
<?php
/**
* @ORM\Entity(repositoryClass="MonngBundle\Repository\DevicesRepository")
* @ORM\Table(name="devices")
*/
class Devices
{
/**
* @var integer
*
* @ORM\Column(name="device_id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="device_name", type="string", length=255, nullable=true, options={"default": ""})
*/
protected $deviceName = '';
/**
* @var string
* @Assert\Ip(version="4")
* @ORM\Column(name="device_ip_v4", type="string", length=20, nullable=true)
*/
protected $deviceIpV4;
...
现在我希望我的Sonata Admin使用此功能对IP进行排序
<?php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\AdminBundle\Route\RouteCollection;
class DevicesAdmin extends AdminClass
{
protected $datagridValues = array(
'_sort_by' => 'INET_ATON(device_ip_v4)',
);
/**
* @param DatagridMapper $datagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$user = $this->getConfigurationPool()->getContainer()->get('security.token_storage')->getToken()->getUser();
parent::configureDatagridFilters($datagridMapper)
->add('id', null, array('label' => 'Scan-ID'))
->add('deviceName', null, array('label' => 'Device-Name'))
->add('deviceIpV4', null, array('show_filter' => true, 'label' => 'IP-Address (V4)', 'sortable' => 'INET_ATON(deviceIpV4)' ))
但我得到:
ProxyQuery {#11119 ▼
#queryBuilder: QueryBuilder {#11120 ▶}
#sortBy: null
#sortOrder: null
#uniqueParameterId: 0
#entityJoinAliases: []
}