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.

Customising the CMS

$summary_fields does not display SS_Datetime fields?


Reply

7 Posts   664 Views

Avatar
_Vince

12 September 2011 at 9:02pm Community Member, 161 Posts

Hi, I have a table of dates

class TournamentDate extends DataObject{
   
   static $db = array(
      "TournamentDateTime" => "SS_Datetime"   
   );   

}

if I view the data in the ModelAdmin, the summary fields consist of the record ID.

If I add

static $summary_fields = array(
      "TournamentDateTime" => "Tournament Date"
);

the ModelAdmin displays nothing. It just says "No items found", even though looking at the tables, I can see there's two records.

Why?

And how do I get around this?

Avatar
swaiba

13 September 2011 at 12:50am Forum Moderator, 1796 Posts

"casting" could be used to work around this, but I do not know why you have no results at the moment

Avatar
_Vince

13 September 2011 at 1:09am Community Member, 161 Posts

Thanks for the reply.

Casting sounds a bit involved. Would I have to overload the SS_Datetime class or the ModelAdmin?

I suspect the problem is that the SS_Datetime is a composite field and that's what complicates matters? But really, I've no idea.

Avatar
swaiba

13 September 2011 at 1:20am Forum Moderator, 1796 Posts

casting isn't too invlolved - but yes it's not coming right out of the box
in my view it's a better option that modifying anything in "cms" or "sahppire"

Avatar
martimiz

13 September 2011 at 4:33am Forum Moderator, 1091 Posts

You're on the right track - the searchbox on the left stumbles on the composite field. Try the following to replace the composite field by a textfield - you can still search on parts of the datetime...

   static $searchable_fields = array(
      'TournamentDateTime' => array(
         'field' => 'TextField'
   ));

Avatar
swaiba

13 September 2011 at 4:42am Forum Moderator, 1796 Posts

ah was that it?

believe it or not I've never used the SS_DateTime - everything is with a Date or a Time in my systems.

you also have the option to manipulate the fields from within...

   public function scaffoldSearchFields() {
    $fields = parent::scaffoldSearchFields();

      return $fields;
   }

And if you want to go to town...
http://www.leftandmain.com/silverstripe-tutorials/2011/03/15/taming-the-beast-remodeling-modeladmin-part-2/

Avatar
martimiz

14 September 2011 at 12:40am Forum Moderator, 1091 Posts

@swaiba: neither had I - and now I'm not going to, I think...

Thanks for the link, I had done some heavy remodelling before, but it's not a bad idea to follow a similar track to what others do... :-)