Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Modifying SummaryFields as they are displayed

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

Page: 1 2
Go to End
Author Topic: 3525 Views
  • timwjohn
    Avatar
    Community Member
    98 Posts

    Modifying SummaryFields as they are displayed Link to this post

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

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    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.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    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?

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    Do you mean sortable by the user in the CMS side? rather than how it is pulled out of the DB in the class?

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    Yeah, that's what I mean.

    Just wondering if there's a feature of SilverStripe that can do this...

  • nicolant
    Avatar
    Community Member
    6 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

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

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    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.

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: Modifying SummaryFields as they are displayed Link to this post

    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

    3525 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.