Browse files

ENHANCEMENT: SSF-106 adding a "no items found" message when returning…

… an empty grid field
  • Loading branch information...
1 parent 2552bae commit e0bd5d107069bc676009c0515aa9a2af0e9f81ef @candidasa candidasa committed Mar 6, 2012
Showing with 27 additions and 17 deletions.
  1. +27 −17 forms/gridfield/GridField.php
View
44 forms/gridfield/GridField.php
@@ -319,25 +319,35 @@ public function FieldHolder() {
}
}
- foreach($list as $idx => $record) {
- $record->iteratorProperties($idx, $list->count());
- $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);
- $rowContent .= $this->createTag('td', $colAttributes, $colContent);
+
+ if ($list->Count() > 0) {
+ foreach($list as $idx => $record) {
+ $record->iteratorProperties($idx, $list->count());
+ $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);
+ $rowContent .= $this->createTag('td', $colAttributes, $colContent);
+ }
+ $row = $this->createTag(
+ 'tr',
+ array(
+ "class" => 'ss-gridfield-item ' . $record->FirstLast() . " " . $record->EvenOdd(),
+ 'data-id' => $record->ID,
+ // TODO Allow per-row customization similar to GridFieldDefaultColumns
+ 'data-class' => $record->ClassName,
+ ),
+ $rowContent
+ );
+ $content['body'][] = $row;
}
+ } else { //display a message when the grid field is empty
$row = $this->createTag(
- 'tr',
- array(
- "class" => 'ss-gridfield-item ' . $record->FirstLast() . " " . $record->EvenOdd(),
- 'data-id' => $record->ID,
- // TODO Allow per-row customization similar to GridFieldDefaultColumns
- 'data-class' => $record->ClassName,
- ),
- $rowContent
+ 'tr',
+ array("class" => 'ss-gridfield-item ss-gridfield-no-items'),
+ $this->createTag('td', array(), _t('GridField.NoItemsFound', 'No items found'))
);
$content['body'][] = $row;
}

0 comments on commit e0bd5d1

Please sign in to comment.