APYDataGridBundle icon indicating copy to clipboard operation
APYDataGridBundle copied to clipboard

Custom mass action with parameters

Open ustrugany opened this issue 12 years ago • 14 comments

Hi there, For starters thanks for excellent bundle!

I have struggling with one thing for some time though.. What I want to accomplish is to create mass action that would consist of two select fields, one would allow you to choose which mass action to apply on grid data, and the second one which will allow to select parameters required by mass action. For example:

Action [assign to group action] [group # 1] Submit action

I could alter blocks.html.twig, but how to intercept parameters for mass action, and pass them to callback that handles particular mass action.

How can this be done?

ustrugany avatar Jan 10 '13 17:01 ustrugany

I think that you can do it with a forward controller callback like AcmeHelloBundle:Hello:fancy. Indeed the doc isn't full updated on this part. You are in a controller so you have access to the request and normally you can get the Group #1 input from the submit action. And the first input assign to group action will be your mass actions.

Do you understand my idea?

Abhoryo avatar Jan 10 '13 22:01 Abhoryo

@Abhoryo Not fully i don't understand forward controller callback part...

You mean passing controller and his method as mass action callback? $callback = array($controllerInstance, 'handleMassaction'); $massAction = new MassAction($title, $callback, $confirm, $parameters, $role);

I build grids in services so I don't have access to controller. When I need to create grid, I execute from controller something like $this->get('some_entity.grid.builder')->build(); and get fully configured grid object.

It would be great if instead of callback i could just give mass action a route to forward to, after executing mass action, but i understand that it is not possible?

ustrugany avatar Jan 11 '13 09:01 ustrugany

The MassAction object accept a callback (see PHP doc) or the name of an controller action (AcmeHelloBundle:Hello:fancy) like the forward function of symfony.

Bundle name: AcmeHelloBundle Controller Class: HelloController Action Method: fancyAction

so this is the same that define a route because a route is associated to a controler action.

Abhoryo avatar Jan 11 '13 10:01 Abhoryo

@Abhoryo Yeah, I confirm this work - thanks. I didn't know that there is such a option, it is not in the docs. So this will allow me to run controller action that handles mass action, get access to container, request, session etc.

Now I have got yet one question, how is to best create this additional field with parameters for mass action, completely override mass action block and write there custom form? Adding field only? Manually searching in Request posted parameter field, seems to be not so elegant approach.

ustrugany avatar Jan 11 '13 11:01 ustrugany

Like you want.

you can also use javascript to change the action url of the mass action form with the additionnal field.

Abhoryo avatar Jan 11 '13 13:01 Abhoryo

It's good for you ?

Abhoryo avatar Jan 21 '13 14:01 Abhoryo

Yeah, I created custom blocks.html.twig with overrided mass actions section, created additional form field for passing extra parameter to mass action callback - controller route. Next I pulled this parameter from Request inside controller action.

ustrugany avatar Jan 24 '13 18:01 ustrugany

Nice.

Abhoryo avatar Jan 24 '13 21:01 Abhoryo

This is my implementation of mass actions with custom form fields that depend on the action. https://gist.github.com/karser/b6e49602d12c9d3d58da This feature it is often useful, maybe it worth to include to the project.

karser avatar May 01 '14 18:05 karser

First, can we avoid jquery? Second, does it work only with a callback or a controller works too ?

Then, I think we can merge this feature in the MassAction class but we need to put the form in a modal dialog.

A user select rows: massaction1

Select a mass action and submit the action: massaction2

A form dialog is displayed. massaction3

Abhoryo avatar May 02 '14 09:05 Abhoryo

  1. APYDataGridBundle already uses jQuery. Nevertheless, we can no use it.
  2. A form handles data from request by Symfony way so doesn't matter is it a callback or a controller. Which modal component do you want to use? Pure JS, like this? http://jsmodal.com/ Btw, what the prototype tool did you use?

karser avatar May 02 '14 13:05 karser

I use moqups. It's lighter than Balsamiq Mockups

  1. The bundle use Jquery only for ajax grid. So yes, I hope we can do this without jquery or other extern libraries. But jsmodal seems good.
  2. Ok, great

In fact, you could already use a form if you put the form object in the parameter of the massAction. You juste need to modiify the template.

Abhoryo avatar May 02 '14 14:05 Abhoryo

a useful feature :+1:

b-durand avatar Feb 10 '15 20:02 b-durand

@karser If you have time, propose a PR. We would like to merge to the project. https://github.com/APY/APYDataGridBundle/issues/328#issuecomment-41939142

hmert avatar Dec 13 '15 23:12 hmert