Skip to content

Commit

Permalink
Add a basic column header component. Closes symbiote#7.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajshort committed Feb 24, 2013
1 parent 8f10ed4 commit ddb66a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 24 additions & 0 deletions code/GridFieldTitleHeader.php
Original file line number Diff line number Diff line change
@@ -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'),
);
}

}
1 change: 1 addition & 0 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions templates/GridFieldTitleHeader.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<tr class="ss-gridfield-title-header">
<% loop $Me %>
<th class="main col-$Name">$Title</th>
<% end_loop %>
</tr>

0 comments on commit ddb66a9

Please sign in to comment.