Jump to:

22979 Posts in 11808 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Add functions to ComplexTableField

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: 364 Views
  • esakrielaart
    Avatar
    Community Member
    53 Posts

    Add functions to ComplexTableField Link to this post

    Hello,

    I wish to add functionality to the ComplexTableField for use in ModelAdmin, that is, add standard buttons like the 'Add/Edit/Delete' which perform a certain taks (in my specific case display a PDF file). How can I achieve this? I read something that I have to edit the summary_fields in my controllerclass, like:

    static $summary_fields = array(
    "Name" => "Name",
    ...
    "PDF" => "PDF"
    );

    public function getPDF() {
    // Do things
    return $output;
    }

    But unfortunately this method did not work, throwing an error that silverstripe was not able to traverse to PDF.

    Does anybody has any experience with this? Thanks in advance,

    Maurice

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: Add functions to ComplexTableField Link to this post

    Just to make sure: this works in my 246 testinstall (for some often misused test object):

       static $summary_fields = array(
          'Name' => 'Name',
          'PDF' => 'PDF'
       );

       function getPDF() {
          return 'test';
       }

    So maybe there's some conflict with a real PDF object, and you could try to rename the field?

    Even returning a link to some url on your site will sort of work, (although it seems to want to try and open the popup as well), but that's about it...

    I think, if you really want some control, and add functionality along the lines of edit, delete... you'd have to extend the CTF and follow the code for these actions...

  • esakrielaart
    Avatar
    Community Member
    53 Posts

    Re: Add functions to ComplexTableField Link to this post

    Hi,

    thanks for the reply. Unfortunately, it does not seem to work, also not using version 2.4.6 and also not after renaming. Could there be a problem, for instance, that the funtion returns just a string instead of a dataobject(set)?

    Thanks in advance,
    Maurice

  • martimiz
    Avatar
    Forum Moderator
    1037 Posts

    Re: Add functions to ComplexTableField Link to this post

    What summary_fields does is try to place the value of the chosen field into the table for each record. You can replace that with a function returning a string or some html, but you cannot feed it some object or even a set of objects...

    So you could use the setup above and have the function returning a link, containing an url on your site, that would in turn generate the pdf for you. Or something along those lines...

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