在listMapper Sonata Admin中更改字段css

时间:2018-02-09 18:34:18

标签: php bundle sonata

我想在listMapper中修改“Benefice”字段的样式。

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->add('date')
            ->add("nombreMatch")
            ->add('cote')
            ->add('mise')
            ->add('gain')
            ->add('benefice',null,array(
            'attr' => array('style' => 'color:red;'),
            ));
    }   
}

我使用“attr”属性但它确实有用。我也尝试“header_style”属性,它确实有效。

如果有人有解决方案,

感谢您的帮助:)

2 个答案:

答案 0 :(得分:0)

您可以在第3个参数中传递自定义tempalate,就像我here一样,或者您可以尝试传递header_style而不是attr here

答案 1 :(得分:0)

我找到了解决方案,谢谢!

对于遇到同样问题的其他人:

 protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id', null ,[
                'header_style' => 'width: 14%',    
            ])
            ->add('date', null ,[
                'header_style' => 'width: 14%',    
            ])
            ->add("nombreMatch", null ,[
                'header_style' => 'width: 14%',    
            ])
            ->add('cote', null ,[
                'header_style' => 'width: 14%',    
            ])
            ->add('mise', null ,[
                'header_style' => 'width: 14%',    
            ])
            ->add('gain', null ,[
                'header_style' => 'width: 14%',    
            ])
           ->add('benefice', null, array('template' => '@SonataAdmin/CRUD/Special/benefice_field_list.html.twig'))
        ;
    }

{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field%}
    <div>
        <strong>{{ object.benefice }}</strong>

    </div>
{% endblock %}
相关问题