Skip to content

Commit 725846f

Browse files
committed
datagrid changes
1 parent 37ba07e commit 725846f

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include field.options.template %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ attribute(item, field.fieldName)|date }}

Service/DataGridService.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
class DataGridService
1313
{
14+
private $itemsPerPage;
1415
/**
1516
* @var TwigEngine
1617
*/
@@ -53,16 +54,20 @@ public function addField($fieldName, $type = 'string', $options = [])
5354
public function setQb($qb)
5455
{
5556
$this->qb = $qb;
57+
}
5658

57-
58-
59-
59+
/**
60+
* @param mixed $itemsPerPage
61+
*/
62+
public function setItemsPerPage($itemsPerPage)
63+
{
64+
$this->itemsPerPage = $itemsPerPage;
6065
}
6166

6267
public function addFiltersToQb()
6368
{
6469
foreach ($this->fields as $field) {
65-
if (isset($field['options'], $field['options']['filterable'])) {
70+
if (isset($field['options'], $field['options']['filterable']) && $field['options']['filterable']) {
6671
$filterParam = $this->requestStack->getCurrentRequest()->query->get('filter');
6772
$this->qb->andWhere('x.'.$field['fieldName'].' LIKE :'.$field['fieldName'])->setParameter($field['fieldName'], '%'.$filterParam[$field['fieldName']].'%');
6873
}
@@ -71,7 +76,7 @@ public function addFiltersToQb()
7176
$this->pagedData = $this->paginator->paginate(
7277
$this->qb->getQuery(), /* query NOT result */
7378
$this->requestStack->getCurrentRequest()->query->getInt('page', 1)/*page number*/,
74-
2/*limit per page*/
79+
$this->itemsPerPage/*limit per page*/
7580
);
7681

7782
}
@@ -83,8 +88,19 @@ public function doCallbacks()
8388
if (isset($field['options'], $field['options']['callback'])) {
8489
foreach ($this->pagedData->getItems() as $item) {
8590
$oldValue = $accessor->getValue($item, $field['fieldName']);
91+
//use item instead of value for callback
8692
$callback = $field['options']['callback'];
87-
$accessor->setValue($item, $field['fieldName'], $callback($oldValue));
93+
$extraCallbackData = [];
94+
if (isset($field['options']['extra_callback_data'])) {
95+
$extraCallbackData = $field['options']['extra_callback_data'];
96+
}
97+
if ($field['type'] == 'custom_callback') {
98+
$item->{$field['fieldName']} = $callback($item, $extraCallbackData);
99+
// /$accessor->setValue($item, $field['fieldName'], $callback($item));
100+
} else {
101+
$accessor->setValue($item, $field['fieldName'], $callback($oldValue, $extraCallbackData));
102+
}
103+
88104
}
89105
}
90106
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"minimum-stability": "dev",
1919
"require": {
20+
"knplabs/knp-paginator-bundle": "2.5.3",
2021
"php": ">=5.3.2"
2122
},
2223
"require-dev": {

0 commit comments

Comments
 (0)