Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Modifying SummaryFields as they are displayed


Go to End


11 Posts   7004 Views

Avatar
timwjohn

Community Member, 98 Posts

5 June 2010 at 1:30am

Edited: 05/06/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...

Avatar
dhensby

Community Member, 253 Posts

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.

Avatar
timwjohn

Community Member, 98 Posts

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?

Avatar
dhensby

Community Member, 253 Posts

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?

Avatar
timwjohn

Community Member, 98 Posts

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...

Avatar
nicolant

Community Member, 6 Posts

2 July 2010 at 11:01pm

Did you find any workaround? I'm facing the same problem.

Avatar
timwjohn

Community Member, 98 Posts

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.

Avatar
martimiz

Forum Moderator, 1391 Posts

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

Go to Top