mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Add a basic column header component. Closes #7.
This commit is contained in:
parent
8f10ed4924
commit
ddb66a9919
@ -8,5 +8,6 @@ This module provides a number of useful grid field components:
|
||||
* `GridFieldAddNewMultiClass` - lets the user select from a list of classes to create a new record from.
|
||||
* `GridFieldEditableColumns` - allows inline editing of records.
|
||||
* `GridFieldOrderableRows` - drag and drop re-ordering of rows.
|
||||
* `GridFieldTitleHeader` - a simple header which displays column titles.
|
||||
|
||||
See [docs/en/index.md](docs/en/index.md) for documentation and examples.
|
||||
|
24
code/GridFieldTitleHeader.php
Normal file
24
code/GridFieldTitleHeader.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* A simple header which displays column titles.
|
||||
*/
|
||||
class GridFieldTitleHeader implements GridField_HTMLProvider {
|
||||
|
||||
public function getHTMLFragments($grid) {
|
||||
$cols = new ArrayList();
|
||||
|
||||
foreach ($grid->getColumns() as $name) {
|
||||
$meta = $grid->getColumnMetadata($name);
|
||||
|
||||
$cols->push(new ArrayData(array(
|
||||
'Name' => $name,
|
||||
'Title' => $meta['title']
|
||||
)));
|
||||
}
|
||||
|
||||
return array(
|
||||
'header' => $cols->renderWith('GridFieldTitleHeader'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -26,6 +26,7 @@ $grid = new GridField(
|
||||
GridFieldConfig::create()
|
||||
->addComponent(new GridFieldButtonRow('before'))
|
||||
->addComponent(new GridFieldToolbarHeader())
|
||||
->addComponent(new GridFieldTitleHeader())
|
||||
->addComponent(new GridFieldEditableColumns())
|
||||
->addComponent(new GridFieldDeleteAction())
|
||||
->addComponent(new GridFieldAddNewInlineButton())
|
||||
|
5
templates/GridFieldTitleHeader.ss
Normal file
5
templates/GridFieldTitleHeader.ss
Normal file
@ -0,0 +1,5 @@
|
||||
<tr class="ss-gridfield-title-header">
|
||||
<% loop $Me %>
|
||||
<th class="main col-$Name">$Title</th>
|
||||
<% end_loop %>
|
||||
</tr>
|
Loading…
Reference in New Issue
Block a user