Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Table Field not displaying 'delete' option for non Administrators

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

Page: 1
Go to End
Author Topic: 1013 Views
  • Spyk
    Community Member
    2 Posts

    Table Field not displaying 'delete' option for non Administrators Link to this post

    Hi there,

    Within my template I have a TableField that is only displaying the Delete icon when the user has Full Administrative rights.
    Does anyone know why my contend editors can't delete data in the TableField?

    Here's the section of code:

    function getCMSFields() {

    $fields = parent::getCMSFields();

    //Program Rank Fields

    $Top10ProgramsTable = new TableField('Top10ProgramsField', 'ProgramRank',array('Rank'=>'Rank','Program'=>'Program', 'Channel'=>'Channel', 'Audience'=>'Audience'), array('Rank'=>'TextField', 'Program'=>'TextField', 'Channel'=>'TextField', 'Audience'=>'TextField'), "MyNewsletterID",$this->ID);

    $Top10ProgramsTable->setExtraData(array('MyNewsletterID' => $this->ID ? $this->ID : '$RecordID'));

    $Top10ProgramsTable->setPermissions(array('edit', 'add', 'delete')); //adding and removing this line doesn't affect the outcome

    return $fields;


    static $has_many = array(
    'Top10Programs' => 'ProgramRank');

    class ProgramRank extends DataObject {

    static $db = array(
    'Rank' => 'Text',
    'Program' => 'Text',
    'Channel' => 'Text',
    'Audience' => 'Text'


    static $has_one = array(
    'MyNewsletter' => 'TwoColumnNewsletter'


    Thank you

  • sktzoootech
    Community Member
    5 Posts

    Re: Table Field not displaying 'delete' option for non Administrators Link to this post

    Hi there,

    I was looking for a solution for the same problem via google but unfortunately I couldn't find one. So I started looking for some answers through the codes found in the core SS framework. I found out that on line 50 of the TableField.ss template, it shows that <% if Can(delete) %> ... <% end_if %> doesn't get executed because Can(delete) is always null within the context of the loop block (lines 44 to 52). So even if you have set the mode to "delete" explicitly via the setPermissions method, it doesn't work.

    So the work around for this issue is to copy the file TableField.ss from the folder "sapphire/templates/" to your themes folder "themes/mysite". After you copy the template file, replace line 50 with <% if Top.Can(delete) %> to make sure the Can method refers to the context outside of the loop block.

    You can actually directly edit the "TableField.ss" which is part of core SS but its bad practice. It is ideal to keep your core files untouched by copying templates that needs revisions to your themes folder. Anyways, the templates found in the themes folder has higher precedence than the ones found in the core SS templates folder.

    I hope the above makes sense to anyone who have the same issue.

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.