mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Allowing custom attributes on GridField, adding more CSS classes to support behaviour
This commit is contained in:
parent
1b4dda491a
commit
5a3242cab7
@ -327,33 +327,45 @@ class GridField extends FormField {
|
|||||||
|
|
||||||
foreach($list as $idx => $record) {
|
foreach($list as $idx => $record) {
|
||||||
$record->iteratorProperties($idx, $list->count());
|
$record->iteratorProperties($idx, $list->count());
|
||||||
$row = "<tr class='".$record->FirstLast()." ".$record->EvenOdd()."'>";
|
$rowContent = '';
|
||||||
foreach($columns as $column) {
|
foreach($columns as $column) {
|
||||||
$colContent = $this->getColumnContent($record, $column);
|
$colContent = $this->getColumnContent($record, $column);
|
||||||
// A return value of null means this columns should be skipped altogether.
|
// A return value of null means this columns should be skipped altogether.
|
||||||
if($colContent === null) continue;
|
if($colContent === null) continue;
|
||||||
$colAttributes = $this->getColumnAttributes($record, $column);
|
$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;
|
$content['body'][] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn into the relevant parts of a table
|
// Turn into the relevant parts of a table
|
||||||
$head = $content['header'] ? $this->createTag('thead', array(), implode("\n", $content['header'])) : '';
|
$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'])) : '';
|
$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,
|
'id' => isset($this->id) ? $this->id : null,
|
||||||
'class' => "field CompositeField {$this->extraClass()}",
|
'class' => "field CompositeField {$this->extraClass()}",
|
||||||
'cellpadding' => '0',
|
'cellpadding' => '0',
|
||||||
'cellspacing' => '0'
|
'cellspacing' => '0'
|
||||||
);
|
);
|
||||||
return
|
return
|
||||||
$this->createTag('fieldset', array('id'=>$this->ID(),'class'=>'ss-gridfield'),
|
$this->createTag('fieldset', $attrs,
|
||||||
implode("\n", $content['before']) .
|
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'])
|
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 %>
|
<% if $GridField.ExtraColumnsCount %>
|
||||||
<% control Fields %>
|
<% control Fields %>
|
||||||
<td>$Value</td>
|
<td>$Value</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user