5093 Posts in 1516 Topics by 1113 members
| Go to End | Next > | |
| Author | Topic: | 2513 Views |
-
Modifying SummaryFields as they are displayed

5 June 2010 at 1:30am Last edited: 5 June 2010 1:31am
Is it possible to modify the display of the SummaryFields as they appear in a list?
Specifically, I've included the LastEdited field in my custom DataObject's SummaryFields, but would like to display it in a friendlier format while still being able to column sort chronologically...
-
Re: Modifying SummaryFields as they are displayed

7 June 2010 at 8:17am
Its pretty simple to customise how the summary fields look for the user.
class myObject extends DataObject {
static $db = array(
'Title' => 'Varchar',
'Date' => 'SSDatetime'
);static $summary_fields = array(
'Title' => 'Title',
'NiceDate' => 'Date
);function getNiceDate() {
return $this->dbObject('Date')->Nice();
}}
This means you can still sort by date, but then show a 'nice' date in the summary fields. Hope that is what you were looking for.
-
Re: Modifying SummaryFields as they are displayed

9 June 2010 at 9:15pm
Thanks for the reply Pigeon.
However, this method wouldn't allow me to sort the NiceDate column. It would just appear unsortable. Only direct database fields are sortable, and NiceDate is just the returned value of a getter. Even if I were to write a nicer version of the date to a database field and sort that, it would be sorted alphanumerically rather than chronologically.
What I was getting at was the possibility of having a field that is altered for display purposes, but remains a sortable date field under the bonnet. Is this possible?
-
Re: Modifying SummaryFields as they are displayed

10 June 2010 at 10:26am
Do you mean sortable by the user in the CMS side? rather than how it is pulled out of the DB in the class?
-
Re: Modifying SummaryFields as they are displayed

10 June 2010 at 8:54pm
Yeah, that's what I mean.
Just wondering if there's a feature of SilverStripe that can do this...
-
Re: Modifying SummaryFields as they are displayed

2 July 2010 at 11:01pm
Did you find any workaround? I'm facing the same problem.
-
Re: Modifying SummaryFields as they are displayed

5 July 2010 at 2:44am
No I didn't I'm afraid. Just displayed the raw dates. It's probably a good idea to put it in as a feature request. I'll do that when I get the chance.
-
Re: Modifying SummaryFields as they are displayed

12 July 2010 at 1:41am
On TableListField (and all classes derived from it) you can influence the way fielddata are displayed in the list by using the setFieldFormatting() method. It receives an array('field name' => 'formatting string'). This will leave the way the field is sorted intact, based on the underlying (db)field value (at least that's what I found).
More info here http://doc.silverstripe.org/tablelistfield. You can use the $NiceDate from the post above in the formatting string (instead of $value).
If you're referring to ModelAdmin: that's far more complex, although it could be done (without the dirty hack, that is
)
Cheers
| 2513 Views | ||
| Go to Top | Next > |



