From 5a3242cab7893c4c3a56ed0640b9a3f1a637320c Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 7 Feb 2012 20:55:54 +0100 Subject: [PATCH] MINOR Allowing custom attributes on GridField, adding more CSS classes to support behaviour --- forms/gridfield/GridField.php | 26 +++++++++++++++++++------- templates/Includes/GridField_Item.ss | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/forms/gridfield/GridField.php b/forms/gridfield/GridField.php index d21158937..d5bcaf96d 100755 --- a/forms/gridfield/GridField.php +++ b/forms/gridfield/GridField.php @@ -327,33 +327,45 @@ class GridField extends FormField { foreach($list as $idx => $record) { $record->iteratorProperties($idx, $list->count()); - $row = ""; + $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 .= ""; + $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']) ); } diff --git a/templates/Includes/GridField_Item.ss b/templates/Includes/GridField_Item.ss index 2b28e2f31..a662b3446 100644 --- a/templates/Includes/GridField_Item.ss +++ b/templates/Includes/GridField_Item.ss @@ -1,4 +1,4 @@ - + <% if $GridField.ExtraColumnsCount %> <% control Fields %> $Value