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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

DataObject > Casting & GridField Sortable


Go to End


958 Views

Avatar
JoeJoe

Community Member, 8 Posts

13 February 2013 at 5:29am

Edited: 13/02/2013 5:29am

Hi Guys,

I want to sort my GridField based on a casted value in my DataObject;

In my DataObject, summary_fields i point to a function DownloadsNum;
static $summary_fields = array(
'FirstName' => 'Varchar',
'Surname' => 'Varchar',
'Email' => 'Varchar(256)',
'DownloadsNum' => 'Downloads'
);

public function DownloadsNum(){
$do = DataObject::get("TrackDownload", "MemberID ='".$this->ID."'");
return $do->count();
}
This is working, i see the values in my GridField. How can i put this column to a descending order by default?

Hope someone can help.
Thx
Joe