Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit c1ee415

Browse files
Add documentation for compute_total
1 parent 403577a commit c1ee415

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

Datatable/Column/AbstractColumn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ public function getTotal()
11651165
/**
11661166
* Set total
11671167
*
1168-
* @param $total
1168+
* @param mixed $total
11691169
*
11701170
* @return $this
11711171
*/

Resources/doc/columns.md

+104-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
6. [Action Column](#6-action-column)
99
7. [Multiselect Column](#7-multiselect-column)
1010
8. [Number Column](#8-number-column)
11+
9. [Attribute Column](#9-number-column)
12+
10. [Link Column](#10-link-column)
1113

1214
## 1. Column
1315

@@ -40,13 +42,18 @@ With 'null' initialized options uses the default value of the DataTables plugin.
4042
| searchable | bool | true | | Enable or disable filtering on the data in this column. |
4143
| title | null or string | null | | Set the column title. |
4244
| visible | bool | true | | Enable or disable the display of this column. |
45+
| sent_in_response | bool | true | | When set to `false`, allows to access to this field in the `$row` array in Closures without sending this column to the browser (parameter `visible` set to `false` only hides the column in the rendered table). |
4346
| width | null or string | null | | Column width assignment. |
4447
| add_if | null or Closure | null | | Add column only if conditions are TRUE. |
4548
| join_type | string | 'leftJoin' | | Join type (default: 'leftJoin'), if the column represents an association. |
4649
| type_of_field | null or string | null (autodetect) | | Set the data type itself for ordering (example: integer instead string). |
4750
| responsive_priority | null or int | null | | Set column's visibility priority. Requires the Responsive extension. |
4851
| filter | array | TextFilter | | A Filter instance for individual filtering. |
4952
| editable | array or null | null | | An Editable instance for in-place editing. |
53+
| mapped | bool | true | | Allow to create columns not mapped in entity neither defined by DQL. |
54+
| is_association | bool | false | | Allow to force if the column is an association, usally used with `mapped` and `data_source`. |
55+
| data_source | null or string | null | | Specify the column source of the data to manipulate in the current column. Usally used with `mapped` and `data_source`. |
56+
| compute_total | bool | false | | Compute the total of numbers of all the row selected by the query. Totals will be displayed on a header row. |
5057

5158
### Example
5259

@@ -225,7 +232,6 @@ ___
225232

226233
Represents a column, optimized for date time values.
227234

228-
**Be sure to install the [Moment.js](https://momentjs.com/) plugin before using this column.**
229235
**Be sure to install the [Bootstrap Date Range Picker](http://www.daterangepicker.com/) plugin before using the DateRangeFilter.**
230236

231237
### Options template
@@ -244,8 +250,7 @@ All options of [Column](#1-column).
244250

245251
| Option | Type | Default | Required | Description |
246252
|-------------|--------|---------|----------|--------------------------|
247-
| date_format | string | lll | | Moment.js date format. |
248-
| timeago | bool | false | | Use the time ago format. |
253+
| date_format | string | lll | | PHP date format. |
249254

250255
### Example
251256

@@ -681,6 +686,7 @@ All options of [Column](#1-column).
681686
| formatter | NumberFormatter Object | | X | A NumberFormatter instance. |
682687
| use_format_currency | bool | false | | Use NumberFormatter::formatCurrency instead NumberFormatter::format to format the value. |
683688
| currency | null or string | NumberFormatter::INTL_CURRENCY_SYMBOL | | The currency code (e.g. EUR). |
689+
| suffix_string | null or string | null | | An optionna string to display after the number. |
684690

685691
### Example
686692

@@ -713,3 +719,98 @@ public function buildDatatable(array $options = array())
713719
}
714720
```
715721
___
722+
## 9. Attribute column
723+
724+
Represents a column, with a `span` tag with `data-*` attributes. The displayed data is in the `span` tag.
725+
726+
727+
### Options template
728+
729+
@SgDatatables/column/attributeColumn.html.twig
730+
731+
### Options
732+
733+
All options of [Column](#1-column).
734+
735+
**Additional:**
736+
737+
| Option | Type | Default | Required | Description |
738+
|---------------------|---------------------------|---------------------------------------|----------|-----------------|
739+
| attributes | null or string or Closure | | X | Attributes to display in `data-*` attributes |
740+
741+
742+
### Example
743+
744+
``` php
745+
public function buildDatatable(array $options = array())
746+
{
747+
// ...
748+
749+
$this->columnBuilder
750+
->add('description', AttributeColumn::class, array(
751+
'title' => 'Message',
752+
'attributes' => function($row) {
753+
return array(
754+
'severity' => $row['severity']
755+
);
756+
}
757+
))
758+
759+
// ...
760+
;
761+
}
762+
```
763+
764+
765+
## 10. Link column
766+
767+
Represents a column, with a link in each cell.
768+
769+
770+
### Options
771+
772+
All options of [Column](#1-column).
773+
774+
**Additional:**
775+
776+
| Option | Type | Default | Required | Description |
777+
|---------------------|---------------------------|---------------------------------------|----------|-----------------|
778+
| route | string | an empty string | | Name of the route to generate. |
779+
| route_params | array or Closure | an empty array | | Parameters needed to generate the route. |
780+
| empty_value | string | an empty string | | String to display if the content is empty. |
781+
| text | null or Closure | null | | An eventual function to transform the text of the link to display. |
782+
| separator | string | an empty string | | The separator between each element to display when there is an association. |
783+
| filterFunction | null or Closure | null | | An eventual function to filter the elements to display if there is an association. |
784+
| email | bool | false | | Generate a link to an email address. |
785+
786+
787+
### Example
788+
789+
``` php
790+
public function buildDatatable(array $options = array())
791+
{
792+
// ...
793+
794+
$this->columnBuilder
795+
->add('referents', LinkColumn::class, array(
796+
'title' => "Referents",
797+
'empty_value' => '<span class="comment">none</span>',
798+
'separator' => ', ',
799+
'filterFunction' => function($projectPerson) {
800+
return $projectPerson['isInChargeOf'] === false; // I want to display only person not in charge, this data is selected with a column with sent_in_response=False
801+
},
802+
'text' => function($projectPerson) {
803+
return $projectPerson['person']['firstName'] . " " . $projectPerson['person']['lastName'];
804+
},
805+
'route' => 'subvention_person_view',
806+
'route_params' => function($projectPerson) {
807+
return array(
808+
'id' => $projectPerson['person']['id']
809+
);
810+
}
811+
))
812+
813+
// ...
814+
;
815+
}
816+
```

0 commit comments

Comments
 (0)