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.

Customising the CMS

Changing value in a column of DataGrid


Reply

11 Posts   779 Views

Avatar
George Botley

16 October 2013 at 1:07pm Community Member, 16 Posts

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.

Avatar
zenmonkey

16 October 2013 at 1:25pm Community Member, 528 Posts

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

Avatar
George Botley

16 October 2013 at 1:39pm Community Member, 16 Posts

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.