-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mass Actions #56
Comments
Currently this is not supported from the grid itself. But you can achieve it yourself. And then over javascript and toolbar buttons..... Sometime i hopefully get this done....maybe you can take a look on it :-) |
Thanks. I'm starting re-factor my application using ZF2 and your module to display my data on tables. At the moment I'm trying understanding your module. I will try contribute as possible :-) |
@ThaDafinser I will try implement Mass Actions on ZfcDatagrid, but first I want discuss some ideas. about how to achieve this.
The user just need set in toolbar or view the code to call (link/button, combobox, etc.) a generic JS function (which was printed by render). The action will be identified by the unique name of each action, which must be the same of html element name/id. What do you think? |
@imonteiro good to hear. here some thoughts from my side: So you can use e.g. a delete action for row and mass action! Example: use ZfcDatagrid\Column;
$delete= new Column\Action\Button();
$delete->setLabel('Delete');
//....and so on
//here is the checkbox action column
$col = new Column\Action();
$col->setLabel(' ');
$col->setUniqueId('actionMass');
$col->setIsMassAction(true); // <-- this is the only difference
$col->addAction($delete);
$grid->addColumn($col);
//...actual selected data columns
//the default row action (like today)
$col = new Column\Action();
$col->setLabel('Actions');
$col->addAction($delete);
$grid->addColumn($col); At server side you can than check if one or more are submitted, over the same action? For the rest i have to think again....but how does this example look for you? Good/bad? |
@ThaDafinser Looks good, with this approach the user can define all on public function prepareViewModel()
if($grid->hasMassActions()) {
$action = new Column\Action\Checkbox();
$action->setAttribute('onclick', 'massActionCheckBox(this)');
$col = new Column\Action('checkboxes');
$col->addAction($action);
$grid->addColumn($col);
} Continuing... But, in your example ZfcDatagrid must throw Exception if more than one The second part... ZfcDatagrid, in this example I will consider bootstrapTable render, will print the JS code when mass action was enabled, to process the checked boxes and fill the hidden form element with postMassIds. For this, we need something like: $massAction = new Mass\Action('uniqueName');
$massAction->setUrl('/action1');
$massAction->setConfirm('Proceed?');
$grid->addMassAction($massAction); and this JS code (isn't tested): function massAction($action)
{
if (postMassIds_.length == 0 || postMassIds_[0] == '')
{
alert('<?php $this->translate('No rows selected!'); ?>');
return false;
}
// TODO: show message, if enabled
document.getElementById('postMassIds').value = postMassIds_
.join(',');
// TODO: POST to action1 url
}
function massActionCheckBox(box)
{
if(box.checked == true)
{
if(postMassIds_[box.value] != 'undefined')
{
postMassIds_.push(box.value);
}
rowsSelected_++;
}else{
if(postMassIds_[box.value] != 'undefined')
{
for(var i=0; i< postMassIds_.length;i++ )
{
if( postMassIds_[i]==box.value)
postMassIds_.splice(i,1);
}
rowsSelected_--;
}
}
// massActionUpdateSelected();
} finally the user, can put whatever he wants something like:
What do you think? Is a good way? |
@imonteiro much input / things to think about. i'll try to give you some feedback tomorrow, so this feature can finally get in 😄 |
@imonteiro haven't forget u...sry for the delay. 🍦 Good things:
Unsure:
"basic" implementation like you suggested:
*** What basic means *** So maye it's better to only provide the parameters (url/title/....) to the view and let the user decide on its own how to display the buttons? E.g. you posted the example with submit...maybe someone wants to it with an Other implementations: |
@imonteiro have it ready in next commit...bootstrapTable + jqGrid support. Only thing missing: confirm...pinging you again when in master |
@ThaDafinser Awesome 👍 I will wait your commit to test. |
@imonteiro pls checkout latest master |
Hi @ThaDafinser, sorry for my late response. I agree with you, the links/buttons should be the user to decide where and how they must appear/look. The buttons render (at footer.phtml) will stay there, or will be optional? (something like: Confirm message isn't implemented, correct? Suggestion... When selecting the checkbox (at title), implement tri-state: none selected (checked=false), page selection (indeterminate), all selected (checked=true). Regarding to post parameters, make sense to pass more than one param? Other than primary key? Good work! 👍 |
Hi @ThaDafinser Regarding Mass Actions I have changed TableRow.php to use the Action\Checkbox class when is active: public function __invoke($row, array $cols, AbstractAction $rowClickAction = null, array $rowStyles = array(), $hasMassActions = false)
{
$return = $this->getTr($row);
if ($hasMassActions === true) {
$checkbox = new Column\Action\Checkbox('massActionSelected[]');
$return .= '<td>' . $checkbox->toHtml($row) . '</td>';
}
foreach ($cols as $col) { This it make sense? If yes, how we can can set attributes to this column? (like classes, etc.) Should be implemented something like you have suggested above? //here is the checkbox action column
$col = new Column\Action();
$col->setLabel(' ');
$col->setUniqueId('actionMass');
$col->setIsMassAction(true); // <-- this is the only difference
$col->addAction($delete);
$col->addClass('i-checks');
$grid->addColumn($col); Regards, |
This issue was moved to zfc-datagrid/zfc-datagrid#6 |
It's possible provide the possibility to perfom some action on multiple rows, by adding an extra column with a checkbox and passing the primary key throw POST.
Example:
The text was updated successfully, but these errors were encountered: