Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Add the column definition method #4

Closed
lenybernard opened this issue Feb 20, 2014 · 0 comments
Closed

Add the column definition method #4

lenybernard opened this issue Feb 20, 2014 · 0 comments
Assignees

Comments

@lenybernard
Copy link
Contributor

@thomasbeaujean created a part of code to define the colmuns directly in the service, we should use it and add the code in the view to generate automatically the list.
No more need to override the default view. Bipbip 👍

PHP :

/**
 * Get column definition
 *
 * @param string  $id         The name of the column of the function of the object
 * @param string  $filter     The name of the filter
 * @param string  $labelId    The id of the label
 * @param boolean $sortable   Can this column be sorted
 * @param string  $sortableId The identifier of the sort
 *
 * @return array The array of a column definition
 */
public function getColumnDefinition($id, $filter = null, $labelId = null, $sortable = false, $sortableId = null)
{
    //by default the id is used for the column label
    if ($labelId === null) {
        $labelId = $id;
    }
    //if sortable, then sortableId is mandatory
    if ($sortable === true) {
        if ($sortableId === null) {
            throw new \Exception('The column '.$id.' is sortable but has no $sortableId defined');
        }
    }
    $column = array(
        'id' => $id,
        'filter' => $filter,
        'label' => $this->getLabelPrefix().$labelId,
        'sortable' => $sortable,
        'sortable_id' => $sortableId
    );
    return $column;
}

html.twig

{% for column in extra.columns %}
    {% if column.sortable %}
    <th class="sortable" data-filter="{{ column.sortable_id }}">{{ column.label|trans }}</th>
    {% else %}
    <th>{{ column.label|trans }}</th>
    {% endif %}
{% endfor %}

We should be able to add a closure to render a column value and define a default column rendering.

lenybernard pushed a commit that referenced this issue Feb 23, 2014
… method.

The default view is now fully usable, no more need to overwrite it for a basic use.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants