Permalink
Browse files

MINOR Allowing custom attributes on GridField, adding more CSS classe…

…s to support behaviour
  • Loading branch information...
1 parent 1b4dda4 commit 5a3242cab7893c4c3a56ed0640b9a3f1a637320c @chillu chillu committed Feb 7, 2012
Showing with 20 additions and 8 deletions.
  1. +19 −7 forms/gridfield/GridField.php
  2. +1 −1 templates/Includes/GridField_Item.ss
@@ -327,33 +327,45 @@ public function FieldHolder() {
foreach($list as $idx => $record) {
$record->iteratorProperties($idx, $list->count());
- $row = "<tr class='".$record->FirstLast()." ".$record->EvenOdd()."'>";
+ $rowContent = '';
foreach($columns as $column) {
$colContent = $this->getColumnContent($record, $column);
// A return value of null means this columns should be skipped altogether.
if($colContent === null) continue;
$colAttributes = $this->getColumnAttributes($record, $column);
- $row .= $this->createTag('td', $colAttributes, $colContent);
+ $rowContent .= $this->createTag('td', $colAttributes, $colContent);
}
- $row .= "</tr>";
+ $row = $this->createTag(
+ 'tr',
+ array(
+ "class" => 'ss-gridfield-item ' . $record->FirstLast() . " " . $record->EvenOdd(),
+ 'data-id' => $record->ID
+ ),
+ $rowContent
+ );
$content['body'][] = $row;
}
// Turn into the relevant parts of a table
$head = $content['header'] ? $this->createTag('thead', array(), implode("\n", $content['header'])) : '';
- $body = $content['body'] ? $this->createTag('tbody', array(), implode("\n", $content['body'])) : '';
+ $body = $content['body'] ? $this->createTag('tbody', array('class' => 'ss-gridfield-items'), implode("\n", $content['body'])) : '';
$foot = $content['footer'] ? $this->createTag('tfoot', array(), implode("\n", $content['footer'])) : '';
- $attrs = array(
+ $this->addExtraClass('ss-gridfield');
+ $attrs = array_diff_key(
+ $this->getAttributes(),
+ array('value' => false, 'type' => false, 'name' => false)
+ );
+ $tableAttrs = array(
'id' => isset($this->id) ? $this->id : null,
'class' => "field CompositeField {$this->extraClass()}",
'cellpadding' => '0',
'cellspacing' => '0'
);
return
- $this->createTag('fieldset', array('id'=>$this->ID(),'class'=>'ss-gridfield'),
+ $this->createTag('fieldset', $attrs,
implode("\n", $content['before']) .
- $this->createTag('table', $attrs, $head."\n".$foot."\n".$body) .
+ $this->createTag('table', $tableAttrs, $head."\n".$foot."\n".$body) .
implode("\n", $content['after'])
);
}
@@ -1,4 +1,4 @@
-<tr class="ss-gridfield-{$EvenOdd} $FirstLast">
+<tr class="ss-gridfield-item ss-gridfield-{$EvenOdd} $FirstLast" data-id="$ID">
<% if $GridField.ExtraColumnsCount %>
<% control Fields %>
<td>$Value</td>

0 comments on commit 5a3242c

Please sign in to comment.