Jump to content

PageTable: Buttons above the pages


KentBrockman
 Share

Recommended Posts

  • 4 weeks later...

There is probably a more robust way to do this, but, uh, I tried :P

$this->addHookAfter('InputfieldPageTable::render', $this, 'PageTableRender');
public function PageTableRender($event) {
	$return = $event->return;

	$from = strrpos($return, "<div class='InputfieldPageTableButtons");
	$to = strrpos($return, "</button></span></div>", $from);

	$buttons = substr($return, $from, $to-$from) . "</button></span></div>";
	
	$event->return = $buttons . $event->return;
}

The Inputfield’s original render method puts the button html in the variable $btn, but I suppose there’s no way to just access that one. Another way to duplicate the button elements would be to just copy the code that generates them.

  • Like 5
Link to comment
Share on other sites

After some more tests it seem's to be a bit buggy.

By creating a new page via the button above the list the new page is generated and saved correctly, but this new page doesn't show up in the list.

When I create a new page via the button under the list the page is generated correctly and a new (second) button appaers above the list. With this new button it is possible to create pages which show up in the list correctly.

Link to comment
Share on other sites

Indeed. Without really looking into it, the Javascript must depend on the position of the buttons. Try this to insert the buttons inside .InputfieldPageTableContainer:

public function PageTableRender($event) {
	$return = $event->return;

	$from = strpos($return, "<div class='InputfieldPageTableButtons");
	$to = strpos($return, "</button></span></div>", $from);
	
	$buttons = substr($return, $from, $to-$from) . "</button></span></div>";
	
	$insertAt = strpos($return, "<table class='AdminDataTable AdminDataList'>");
			
	$event->return = substr_replace($return, $buttons, $insertAt, 0);
}

Instead of this hackish string trickery, perhaps a better way to clone/move the buttons would be to use Javascript in the first place. I’m not sure how to best pull that off. Just append a script tag to $event->return?

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