浏览代码

Merge pull request #3191 from qsomazzi/improve_grid

Add grid customisation
Thomas 9 年之前
父节点
当前提交
3d8a451f62

+ 23 - 0
Resources/doc/reference/action_list.rst

@@ -458,4 +458,27 @@ To do:
 - targeting submodel fields using dot-separated notation
 - advanced filter options (global_search)
 
+Visual configuration
+--------------------
+
+You have the possibility to configure your List View to customize the render without overring to whole template.
+You can :
+
+- `header_style`: Customize the style of header (width, color, background, align...)
+- `header_class`: Customize the class of the header
+- `row_align`:    Customize the alignment of the rendered inner cells
+
+.. code-block:: php
+
+    <?php
+
+    public function configureListFields(ListMapper $list)
+    {
+        $list
+            ->add('id', null, array('header_style' => 'width: 5%; text-align: center', 'row_align' => 'center'))
+            ->add('name', 'text', array('header_style' => 'width: 35%')
+            ->add('actions', null, array('header_class' => 'customActions', 'row_align' => 'right')
+        ;
+    }
+
 .. _`issues on GitHub`: https://github.com/sonata-project/SonataAdminBundle/issues/1519

+ 1 - 1
Resources/views/CRUD/base_list.html.twig

@@ -63,7 +63,7 @@ file that was distributed with this source code.
                                             {% endif %}
 
                                             {% spaceless %}
-                                                <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if sortable %} sonata-ba-list-field-header-order-{{ sort_by|lower }} {{ sort_active_class }}{% endif %}">
+                                                <th class="sonata-ba-list-field-header-{{ field_description.type}} {% if sortable %} sonata-ba-list-field-header-order-{{ sort_by|lower }} {{ sort_active_class }}{% endif %}{% if field_description.options.header_class is defined %} {{ field_description.options.header_class }}{% endif %}"{% if field_description.options.header_style is defined %} style="{{ field_description.options.header_style }}"{% endif %}>
                                                     {% if sortable %}<a href="{{ admin.generateUrl('list', sort_parameters) }}">{% endif %}
                                                     {{ admin.trans(field_description.label, {}, field_description.translationDomain) }}
                                                     {% if sortable %}</a>{% endif %}

+ 1 - 1
Resources/views/CRUD/base_list_field.html.twig

@@ -9,7 +9,7 @@ file that was distributed with this source code.
 
 #}
 
-<td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}">
+<td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}" objectId="{{ admin.id(object) }}"{% if field_description.options.row_align is defined %} style="text-align:{{ field_description.options.row_align }}"{% endif %}>
     {% set route = field_description.options.route.name|default(null) %}
     {% set action = route == 'show' ? 'VIEW' : route|upper %}