Jump to:

3450 Posts in 1063 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » renaming columntitles of listview in modeladmin

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

Page: 1
Go to End
Author Topic: 1713 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    renaming columntitles of listview in modeladmin Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: renaming columntitles of listview in modeladmin Link to this post

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

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

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: renaming columntitles of listview in modeladmin Link to this post

    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?

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: renaming columntitles of listview in modeladmin Link to this post

    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?

  • Terry Apodaca
    Avatar
    Community Member
    109 Posts

    Re: renaming columntitles of listview in modeladmin Link to this post

    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.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: renaming columntitles of listview in modeladmin Link to this post

    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.

    1713 Views
Page: 1
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.