Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Show Relating DataObject as link? (Plus speed up record view in model admin)

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1364 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Show Relating DataObject as link? (Plus speed up record view in model admin) Link to this post

    Hi,

    I have several relations ($has_one) that are slowing down the speed of browsing the record inside model admin - because the relating table has a lot of rows and it is read ALL rows to create the drop down.

    class ExampleObject extends DataObject
    {
       static $db = array(
          'Stuff' => 'Text',
       );

       static $has_one = array(
          'RelationToBigTable' => 'BigTable',
       );
    }

    So I changed them to be read only text fields (as they are not for changing in the gui anyway!).

    class ExampleObject extends DataObject
    {
       static $db = array(
          'Stuff' => 'Text',
       );

       static $has_one = array(
          'RelationToBigTable' => 'BigTable',
       );

       function getCMSFields()
       {
          $fields = parent::getCMSFields();

          $fields->insertAfter(new ReadonlyField('readonlyfield','RelationToBigTableID',$this->RelationToBigTableID),'Stuff');
          $fields->removeByName('RelationToBigTableID');

          return $fields;
       }
    }

    I wonder if there is a way to link them to the other dataobject (also in the same model admin) so that I could turn it into a link and it would jump to editing that record?

    Barry

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Show Relating DataObject as link? (Plus speed up record view in model admin) Link to this post

    Hi,

    On the off chance that this is of use to someone... here is the answer to my own question...

    function getCMSFields()
    {
       ...
       $fields->insertBefore(
          new LiteralField('testlit', "<button onClick=\"jQuery('#ModelAdminPanel').fn('loadForm',
             'admin/<adminsection*>/<DataObject*>/<id*>/edit',function() {})\"> <buttonlabel*></button>"),'ExtraID');
       ...
    }

    * fields need completing

    Barry

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Show Relating DataObject as link? (Plus speed up record view in model admin) Link to this post

    I need this but i where do I need to put it ?? In the Dataobject ?

  • purplespider
    Avatar
    Community Member
    81 Posts

    Re: Show Relating DataObject as link? (Plus speed up record view in model admin) Link to this post

    I'm interested in how to do this too, do let me know if you work it out.

    Cheers

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Show Relating DataObject as link? (Plus speed up record view in model admin) Link to this post

    where do I need to put it ?? In the Dataobject ?

    yes

    also I should point out I now use this rarely as I use this instead now...

    $hasOneCTF = new HasOneComplexTableField($this,DATAOBJECTNAME,DATAOBJECTNAME,null,null,'ID='.$this->DATAOBJECTNAMEID);
    $hasOneCTF->setPermissions(array('edit','show'));
    $hasOneCTF->Markable = false;
    $fields->addFieldToTab("Root.DATAOBJECTNAME", $hasOneCTF);

    and the above link is actually the js called when tapping the edit button on the tab created by teh above code..

    1364 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.