ENHANCEMENT Added correct styling of sorting and odd even on grid table

This commit is contained in:
Stig Lindqvist 2011-09-30 10:59:52 +13:00
parent b1b1615a58
commit 488734e53e
2 changed files with 22 additions and 7 deletions

View File

@ -67,14 +67,17 @@ class DatagridPresenter extends ViewableData {
* *
* @return ArrayList * @return ArrayList
*/ */
function Items() { public function Items() {
$fieldItems = new ArrayList(); $fieldItems = new ArrayList();
if($items = $this->datagrid->datasource) { if($items = $this->getDatagrid()->getDatasource()) {
$counter = 0;
foreach($items as $item) { foreach($items as $item) {
if(!$item) { if(!$item) {
continue; continue;
} }
$fieldItems->push(new $this->itemClass($item, $this)); $datagridPresenterItem = new $this->itemClass($item, $this);
$datagridPresenterItem->iteratorProperties($counter++, $items->count());
$fieldItems->push($datagridPresenterItem);
} }
} }
return $fieldItems; return $fieldItems;
@ -136,8 +139,17 @@ class DatagridPresenter extends ViewableData {
protected function summaryFieldsToList($summaryFields) { protected function summaryFieldsToList($summaryFields) {
$fieldHeaders = new ArrayList(); $fieldHeaders = new ArrayList();
if (is_array($summaryFields)){ if (is_array($summaryFields)){
$counter = 0;
foreach ($summaryFields as $name=>$title){ foreach ($summaryFields as $name=>$title){
$fieldHeaders->push(new ArrayData(array('Name'=>$name, 'Title'=>$title))); $arrayData = new ArrayData(array(
'Name'=>$name,
'Title'=>$title,
'IsSortable'=>true,
'IsSorted'=>false,
'SortedDirection'=>'desc')
);
$arrayData->iteratorProperties($counter++, count($summaryFields));
$fieldHeaders->push($arrayData);
} }
} }
return $fieldHeaders; return $fieldHeaders;
@ -213,6 +225,7 @@ class DatagridPresenter_Item extends ViewableData {
return $this->parent; return $this->parent;
} }
/** /**
* *
* @param bool $xmlSafe * @param bool $xmlSafe
@ -221,7 +234,7 @@ class DatagridPresenter_Item extends ViewableData {
public function Fields($xmlSafe = true) { public function Fields($xmlSafe = true) {
$list = $this->parent->FieldList(); $list = $this->parent->FieldList();
$counter = 0;
foreach($list as $fieldName => $fieldTitle) { foreach($list as $fieldName => $fieldTitle) {
$value = ""; $value = "";
@ -267,11 +280,13 @@ class DatagridPresenter_Item extends ViewableData {
} }
} }
$fields[] = new ArrayData(array( $arrayData = new ArrayData(array(
"Name" => $fieldName, "Name" => $fieldName,
"Title" => $fieldTitle, "Title" => $fieldTitle,
"Value" => $value "Value" => $value
)); ));
$arrayData->iteratorProperties($counter++, count($list));
$fields[] = $arrayData;
} }
return new ArrayList($fields); return new ArrayList($fields);
} }

View File

@ -6,7 +6,7 @@
<thead> <thead>
<tr> <tr>
<% control Headers %> <% control Headers %>
<th class="<% if FirstLast %>ss-datagrid-{$FirstLast}<% end_if %> <% if IsSortable %>ss-datagrid-sortable<% end_if %> <% if IsSorted %>ss-datagrid-sorted ss-datagrid-{$SortedDirection}<% end_if %>"> <th class="<% if FirstLast %>ss-datagrid-{$FirstLast}<% end_if %><% if IsSortable %> ss-datagrid-sortable<% end_if %><% if IsSorted %> ss-datagrid-sorted ss-datagrid-{$SortedDirection}<% end_if %>">
$Title <span class="ui-icon"></span></th> $Title <span class="ui-icon"></span></th>
<% end_control %> <% end_control %>
</tr> </tr>