Jump to content

How to add only one button to custom module that uses lister


Federico
 Share

Recommended Posts

Hello everyone,

I am using a custom module with lister, which works just fine. The only thing that troubles me is how to display only one button at the top, instead of many duplicates that the lister module generates. here couple of snapshots to show it

This is the button (green one on top right) on the header, which is the expected position. So the header looks perfect, whereas in the footer the module generates automatically two additional buttons (not wanted) 

5a23c043d5900_ScreenShot2017-12-03at9_54_57AM.thumb.png.c75d235bd152c4f0c02645098feedc8f.png

5a23c0df14380_ScreenShot2017-12-03at9_55_07AM.thumb.png.b149742b4d65383010ef6570168a448a.png

 

 

the code to generates the lister and the button is all in ___execute() function. Here's the code

$btnAddNew = $this->modules->get("InputfieldButton"); 
$btnAddNew->showInHeader();
$btnAddNew->href = "{$this->wire('config')->urls->admin}page/add/?parent_id=1101";
$btnAddNew->icon = 'plus-circle';
$btnAddNew->value = "Create new project code";
$btnAddNew->aclass = "classeAnchor";
$btnAddNew->addClass = "pw-modal";
$btnAddNew->id = "Test";

$pl = $this->modules->get("ProcessPageLister");

return  $pl->execute() . $btnAddNew->render();

I've also tried this lister option:

$pl->toggles = array('collapseFilters', 'noButtons'); // setting the deafult filter as collapsed, and no additional buttons

but no luck for me. Then also I'm experiencing problem with the modal window for the button, as when I click the button the modal appear and abruptly redirects to add page section of PW, outside of the modal. But this is just a different issue..

Any help would be much appreciated

Link to comment
Share on other sites

On 03/12/2017 at 10:22 PM, Federico said:

So the header looks perfect, whereas in the footer the module generates automatically two additional buttons (not wanted)

One button in the footer is expected - you are appending the rendered button to the Lister output after all. So there is just a single unexpected button being added.

I think this is because your execute() method is called twice, once when the page is first rendered and once in an AJAX request from Lister. So you can make the rendering of the button conditional on it not being an AJAX request.

$pl = $this->modules->get("ProcessPageLister");
$out = $pl->execute();
if(!$this->config->ajax) $out .= $btnAddNew->render();
return $out;

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...