Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Changing value in a column of DataGrid

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

Page: 1 2
Go to End
Author Topic: 745 Views
  • George Botley
    Avatar
    Community Member
    16 Posts

    Re: Changing value in a column of DataGrid Link to this post

    Thanks zenmonkey, I will look at your code and see the changes you made to see if I can finally get my head around this..

    As for your recommendation, that is what I am already doing am I not.. in the sense that the category ID is stored in the Article.

    My reasoning for doing this is that should someone want to change the category name at a later date then they could.

    Sorry to be a pain.. Is there a change I need to make here to.

  • zenmonkey
    Avatar
    Community Member
    528 Posts

    Re: Changing value in a column of DataGrid Link to this post

    You are setting a relation the way you're doing it but manually. If you want to get the Category Title you need to write your own database call, but if you set the relation via a $has_one $has_many, SilverStripe will do all the relation getting and joins for you. If you want to keep it the way you have it now, you can get the Category Title by creating a custom getter.

    function getCategoryTitle() {
    $catergory = ArticleCatagory::get()->byID($this->Category);
    return $category->Title;
    }

    Then you'll be able to show it a gridfield by using CategoryTitle instead of Title

  • George Botley
    Avatar
    Community Member
    16 Posts

    Re: Changing value in a column of DataGrid Link to this post

    Right,

    I understand it now. It now links together, and what's funny with SilverStripe is you always try to make something work in a more complex way, when really.. under the hood is a simple solution to most problems.

    Thanks zenmonkey, your the man. Don't suppose you could check out my other post on getCMSValidator within DataObject?

    George.

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