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.

Data Model Questions /

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

renaming columntitles of listview in modeladmin


Go to End


6 Posts   2594 Views

Avatar
theAlien

Community Member, 131 Posts

6 January 2010 at 4:47am

hi,

I'm wondering if it is possible to rename the columntitles of the resultslist in modeladmin.

that would be usefull if the data are retrieved in a more complex way. For exampe:

	static $summary_fields = array( 
		'MyData.Data'
	);

will echo the following columntitle: "My Data Data", while just "Data" would do fine (and be less ugly ;-) ).

I tried the following (a parallel with $searchable_fields):

	static $summary_fields = array(
		'MyData.Data'=>array('title'=>'Data') 
	);

But that throws an error. Does someone know a solution?

Avatar
Willr

Forum Moderator, 5523 Posts

6 January 2010 at 9:31am

I'm pretty sure you can just do the title as the array value

static $summary_fields = array( 
'MyData.Data' => 'Data Column'
);

Avatar
theAlien

Community Member, 131 Posts

7 January 2010 at 9:33am

Hi Willr,

Thanks for your reply. At first I slammed my head: so simple a solution, it just has to be true...

But unfortunately, it doesn't work: either the column disappears (in case of 'MyData.Data' => 'Data Column') as a whole, or only the data in the column disappear (in case of renaming the column: 'Data'=>'Data Column').

Maybe someone has another idea?

Avatar
Terry Apodaca

Community Member, 112 Posts

6 March 2010 at 12:40pm

sometimes it works and sometimes it doesn't. I can't get it to work consistently with the simple example that Will gave. Has anyone else tried to rename the columns of the grid in the ModelAdmin?

Maybe this is a good place to implement the DOM plugin since it's so much more robust?

Avatar
Terry Apodaca

Community Member, 112 Posts

6 March 2010 at 12:52pm

ACTUALLY...i just found the answer to this. the more i learn about SS the more i fall in love with it!!!

After you have defined your $summary_fields:

static $summary_fields = array(
		'ListingType.ListingType',
		'PropertyType.PropertyType',
		'Name',
		'Address',
		'City',
		'State.StateName',
		'ZipCode',
	);

You can/need to the define the labels:

	
	static $field_labels = array(
		'ListingType.ListingType' => 'Listing Type',
		'PropertyType.PropertyType' => 'Property Type',
                'State.StateName' => 'State',
	);

I like this method...because it keeps everything in your model settings. very nice, though i also agree that it should have simply worked in the example Will gave. that would have been even better.

Avatar
timwjohn

Community Member, 98 Posts

4 April 2010 at 5:56am

Nice.

$field_labels is a cleaner way of defining the labels, rather than doing it 'inline'. It means the labels are unified wherever you display them e.g. in $search_fields and in $summary_fields. No need to define them more than once.