Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ All Options of TextColumn.

| Option | Type | Default | Description |
| ----------- | ------ | ------- | ------------------------------------------------------------ |
| routeName | string | null | route name. This option is required. |
| routeParams | array | ["id"] | Array of property value names for the route parameters. By default is `id` set. |
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["class" => "btn btn-success"]` is formatted as `title="btn btn-success"`. |
| routeName | string | null | Route name. This option is required. |
| routeParams | array | [] | Array of route parameters. The key is the parameter of the route. The value is the property path. |
| attr | array | [ ] | Array of any number of attributes formatted as HTML attributes. The array `["class" => "btn btn-success"]` is formatted as `class="btn btn-success"`. |

#### Example

Expand All @@ -442,10 +442,32 @@ use HelloSebastian\HelloBootstrapTableBundle\Columns\LinkColumn;

->add('department.name', LinkColumn::class, array(
'title' => 'Department',
'routeName' => 'show_department' // this option is required
'routeName' => 'show_department', // this option is required
'routeParams' => array(
'id' => 'department.id' // "id" is the route parameter of "show_department". "department.id" is the property path to fetch the value for the route parameter.
)
))
```

If the route parameters cannot be determined automatically based on the entity, user-defined routes can be created by overwriting `data`. Once `data` is overwritten, `routeName` and `routeParams` are no longer necessary to specify.

```php
use HelloSebastian\HelloBootstrapTableBundle\Columns\LinkColumn;

->add('department.name', LinkColumn::class, array(
'title' => 'Department',
'data' => function (User $user) {
return array(
'displayName' => $user->getDepartment()->getName(),
'route' => $this->router->generate('show_department', array('some_parameter' => 'Hello'),
'attr' => ''
);
}
))
```



---

### CountColumn
Expand Down Expand Up @@ -1072,4 +1094,4 @@ class UserTable extends HelloBootstrapTable

## Contributing

Contributions are **welcome** and will be credited.
Contributions are **welcome** and will be credited.
6 changes: 3 additions & 3 deletions src/Columns/LinkColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function configureOutputOptions(OptionsResolver $resolver)

$resolver->setDefaults(array(
"routeName" => null,
"routeParams" => array("id"),
"routeParams" => array(),
"attr" => array(),
"formatter" => "defaultLinkFormatter"
));
Expand All @@ -33,8 +33,8 @@ public function buildData($entity)
}

$routeParams = array();
foreach ($this->outputOptions['routeParams'] as $param) {
$routeParams[$param] = $this->propertyAccessor->getValue($entity, $param);
foreach ($this->outputOptions['routeParams'] as $routeParam => $paramPath) {
$routeParams[$routeParam] = $this->propertyAccessor->getValue($entity, $paramPath);
}

return array(
Expand Down