Add a basic column header component. Closes #7.

This commit is contained in:
ajshort 2013-02-24 11:09:14 +11:00
parent 8f10ed4924
commit ddb66a9919
4 changed files with 31 additions and 0 deletions

View File

@ -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.

View 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'),
);
}
}

View File

@ -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())

View File

@ -0,0 +1,5 @@
<tr class="ss-gridfield-title-header">
<% loop $Me %>
<th class="main col-$Name">$Title</th>
<% end_loop %>
</tr>