SS3.6 Sortable Rows

Tags: #<Tag:0x00007f0827267e98>


Silverstripe Version: 3.6

Question: I was wondering on how to set up only a/or few selected/defined columns as sortable in a gridfield.

Can anyone point me in the right direction please?



Hi @huchakke the ability to click a column header to change the displayed sort order is usually determined automatically… If you go deep in to a gridfield you can probably influence this but it might be more trouble than it’s worth. Is it harmful in your case to allow users to sort on whichever columns they like?

Off the top of my head one quick/hacky way you could do it is to to delegate a method to provide a display value instead of a database field, since you can’t sort on method results. So if you have a DB field named ‘Title’ and you don’t want that to be sortable you could tell the gridfield to display ‘myTitle’ instead, and have a myTitle() method which just returns $this->Title. You can configure the GridField directly or use $summary_fields if you don’t ever want scaffolded interfaces to be able to sort on that field.