GridField return ‘No Items Found’

First thing you need to check is the related object of the data source of the Gridfield is viewable or not. For example, if you need to manage the has_one Profile object of class Member, you need to define this method in your profile


class Profile extends DataObject {

static $has_one = array('owner'=>'Member');

public function canView($member=null){
if($member ==null ) $member = Member::currentUser();
if($member ==null | $member->ID < 1 ) return false; if($member->ID == $this->OwnerID ) return true;

if(Permission::check('ADMIN')) return true;

return false;
}

}

Then in your Member extension class


class MemberExtension extends DataExtension {
function updateCMSFields(FieldList $fields) {
$config = GridFieldConfig::create();
$config->addComponent(new GridFieldToolbarHeader());
$config->addComponent(new GridFieldDetailForm());
$profileFd = new GridField("Profile", "Profile",$this->owner->Profile(), $config);
$fields->addFieldToTab('Root.Profile', $profileFd);

}
}

This entry was posted in Silverstripe. Bookmark the permalink.