【问题标题】:Change field css in listMapper Sonata Admin在 listMapper Sonata Admin 中更改字段 css
【发布时间】:2018-07-20 14:14:37
【问题描述】:

我想修改 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”属性,它确实有效。

如果有人有解决方案,

感谢您的帮助:)

【问题讨论】:

    标签: php bundle sonata


    【解决方案1】:

    您可以在第三个参数中传递自定义模板,就像我所做的here 一样,或者您可以尝试传递header_style 而不是attr,如here 所述。

    【讨论】:

    • @zbeb 尝试标题样式而不是 attr?
    • @zbeb 我用文档链接更新了我的答案,这应该对你有所帮助。
    • 它不起作用:->add('benefice',null,array('attr' => array('header_style', 'color:red')))
    • ->add('benefice',null,array('header_style' => 'color:red') ) @zbeb
    • 我不想自定义标题,但列表中的数据:)
    【解决方案2】:

    我找到了解决办法,谢谢!

    对于其他有同样问题的人:

     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 %}
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-04-12
      • 2012-02-09
      相关资源
      最近更新 更多