Skip to content

Commit

Permalink
Merge pull request #656 from plfort/master
Browse files Browse the repository at this point in the history
Add useGridPrefix property to column
  • Loading branch information
Petit Yoann committed Dec 19, 2014
2 parents 285059b + 11d6572 commit 6809f9d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
18 changes: 17 additions & 1 deletion Grid/Column/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ abstract class Column
protected $class;
protected $isManualField;
protected $isAggregate;
protected $usePrefixTitle;

protected $dataJunction = self::DATA_CONJUNCTION;

Expand Down Expand Up @@ -128,7 +129,8 @@ public function __initialize(array $params)
$this->setOperatorsVisible($this->getParam('operatorsVisible', true));
$this->setIsManualField($this->getParam('isManualField', false));
$this->setIsAggregate($this->getParam('isAggregate', false));

$this->setUsePrefixTitle($this->getParam('usePrefixTitle', true));

// Order is important for the order display
$this->setOperators($this->getParam('operators', array(
self::OPERATOR_EQ,
Expand Down Expand Up @@ -898,4 +900,18 @@ public function getIsAggregate()
{
return $this->isAggregate;
}

public function getUsePrefixTitle()
{
return $this->usePrefixTitle;
}

public function setUsePrefixTitle($usePrefixTitle)
{
$this->usePrefixTitle = $usePrefixTitle;
return $this;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Product
|values|array|_none_||For select filters or replace values in the grid|
|searchOnClick|boolean|false|true or false|Sets the possibility to perform a search on the clicked cell (filterable has to be true)|
|safe|string or false|html|false<br />or<br />see [Escape filters](http://twig.sensiolabs.org/doc/filters/escape.html)|Sets the escape filter|

|usePrefixTitle|boolean|true|true or false|Use the prefixTitle of the grid to render title|
**Note 1**: Every attribute has a setter and a getter method.
**Note 2**: With the `values` attributes, if `type1` is found, the grid displays the value `Type 1`.
**Note 3**: If operators are not visible, filtering is performed with the default operator.
Expand Down
18 changes: 13 additions & 5 deletions Resources/views/blocks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@
{%- spaceless %}
{% if column.type == 'massaction' %}
<input type="checkbox" class="grid-mass-selector" onclick="{{ grid.hash }}_markVisible(this.checked);"/>
{% else %}
{% set columnTitle = grid.prefixTitle ~ column.title ~ '__abbr' %}
{% if columnTitle|trans == columnTitle %}
{% set columnTitle = grid.prefixTitle ~ column.title %}
{% else %}
{% if column.usePrefixTitle == true %}
{% set columnTitle = grid.prefixTitle ~ column.title ~ '__abbr' %}
{% if columnTitle|trans == columnTitle %}
{% set columnTitle = grid.prefixTitle ~ column.title %}
{% endif %}
{% else %}
{% set columnTitle = column.title %}
{% endif %}
{% if (column.sortable) %}
<a class="order" href="{{ grid_url('order', grid, column) }}" title="{{ 'Order by'|trans }} {{ columnTitle|trans }}">{{ columnTitle|trans }}</a>
Expand Down Expand Up @@ -103,7 +107,11 @@
<form id="{{ grid.hash }}_search" action="{{ grid.routeUrl }}" method="post">
{% for column in grid.columns %}
{% if column.isFilterable and column.type not in ['actions', 'massaction'] %}
{% set columnTitle = grid.prefixTitle ~ column.title %}
{% if column.usePrefixTitle == true %}
{% set columnTitle = grid.prefixTitle ~ column.title %}
{% else %}
{% set columnTitle = column.title %}
{% endif %}
<div class="{{ cycle(['odd', 'even'], loop.index) }}"><label>{{ columnTitle|trans }}</label>{{ grid_filter(column, grid, false)|raw }}</div>
{% endif %}
{% endfor %}
Expand Down

0 comments on commit 6809f9d

Please sign in to comment.