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.

General Questions /

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

Add functions to ComplexTableField


Reply


4 Posts   506 Views

Avatar
esakrielaart

Community Member, 58 Posts

13 November 2011 at 12:56am

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

Avatar
martimiz

Forum Moderator, 1132 Posts

13 November 2011 at 1:41am

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

Avatar
esakrielaart

Community Member, 58 Posts

17 November 2011 at 5:34am

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

Avatar
martimiz

Forum Moderator, 1132 Posts

17 November 2011 at 7:24am

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