Crud: [Feature req][3.4] Custom bulk buttons

Created on 15 Jun 2016  路  12Comments  路  Source: Laravel-Backpack/CRUD

In the future, I foresee the need of checkboxes in the first table column and having bulk buttons at the top/bottom of the table, for bulk actions.

screen shot 2016-06-15 at 18 39 34
crude screenshot

This is the proposed syntax for that:

$this->crud->addBulkButton('name', 'url_to_send_a_post_request_with_their_ids');
$this->crud->setBulkButtonsOrder(['send_email', 'delete']);

Any better solutions?

pending question

Most helpful comment

BOOM! Bulk buttons are almost here - finally been able to make this a priority :-)

If you have time, please check out this PR and let me know what you think.

Cheers!

All 12 comments

Why I really like this package is, that this is what I miss in Laravel, that Silverstripe has done very well with their ModelAdmin and GridField.

Its not perfect, but it allows very fast scaffolding of models, relations and admin screens.

https://docs.silverstripe.org/en/3.1/developer_guides/customising_the_admin_interface/modeladmin/

https://www.google.nl/search?q=silverstripe+gridfield&client=firefox-b&source=lnms&tbm=isch&sa=X&ved=0ahUKEwj-59yusKrNAhWDuBoKHeCGA2IQ_AUICCgB&biw=1608&bih=926

It has a intelligent FormScaffolder that guesses fieldnames based on model fields and takes care of the relations.
This does sits in the way, when it gets more complicated, I have to admin that.

The GridField allows to have many different GridFieldConfigs:

https://github.com/silverstripe/silverstripe-framework/blob/master/forms/gridfield/GridFieldConfig.php#L163

And its pretty easy to extend :

https://github.com/silverstripe-australia/silverstripe-gridfieldextensions

These things is what I really mis for Laravel and if this package could provide something like that....
I only need a good SiteTree ;)

@axyr , I think that's exactly what I have in mind with $this->crud->setFromDb()
Sure, right now its laughable how simple it is, but in time setFromDb() should be able to correctly guess a lot of things: columns, column types, fields, field types, relationships, etc. But let's focus on custom bulk buttons in this thread ;-)

We have a need for something like this now, and I suggested to one of the developers to build it and make a pull request but for what I've seen pull requests take a long time to get merged. If we were to fund this feature for one of the developers would it take a long time to get pulled in?

Hi @imcodingideas - I've been away for 2 months, so yes, PRs have been piling up. Can't guarantee that it gets merged immediately - it depends on how complete the PR is and how much more work it needs. PRs are helpful, but they can rarely be merged as-is.

But you can easily achieve the functionality for your own project, using a custom column that has a checkbox with the entry id and a custom button that on click does something to all the selected entries.

That's for the non-ajax-datatable. For the ajax datatable... well... that's where this gets tricky, and what makes me think a PR won't be mergeable as is, unfortunately.

Hi @tabacitu , im trying your proposal to create a button and change one column value for each checked table row. How can achieve this? I mean how can I get all checked rows with a button? Should I do via AJAX?

Thanks.

@Romerski I found this example to be particularly useful.

Since Backpack\CRUD 3.3, when all datatables use AJAX, I think it would be a lot easier to use a custom list.blade.php file for the CRUD you want to have checkboxes, and edit there whatever you want. You can do that using $this->crud->setListView('your-view');.

Hope it helps. Cheers!

@tabacitu Thanks. Trying it.

Just added a column with id of each row with

$this->crud->addColumn([ 'name' => 'id', 'label' => 'checkbox', ]);

Then add

"columnDefs": [ { "targets": 0, "checkboxes": { "selectRow": true } } ], "select": { "style": "multi" }, "order": [[1, "asc"]],

on $("#crudTable").DataTable({ after "ajax": { "url": "{!! url($crud->route.'/search').'?'.Request::getQueryString() !!}", "type": "POST" }, but I dont know why ID of each row appears instead of checkbox :( I have added js an css checkboxes files and browser console outputs no errors.

Already required dataTables.checkboxes.css/js and dataTables.select.css/js

Im trying this with TagCrudController.php on backpack-demo. Any thoughts?

Don't know, sorry, haven't used this myself yet...

@Romerski I was able to make it work, but by replacing the DataTable from Backpack\Base with a new one from datatables download section (with the Select plugin included in Js and Css).

Backpack/Base require AdminLTE 2.3.* via composer and AdminLTE seem to be 2.4.* with a 1.10.* of DataTable.
With all the new changes that are made to CRUD for 3.4, the dataTable version will be updated in Backpack/Base I assume.

With BP/CRUD 3.4.4, this work with the official select plugin from Datatable team.

You must indeed include the plugin with cnd (seem only possible with the download tool) so I downloaded it and include it from my structure :
This is added localy :
<script src="{{ asset('vendor/backpack/datatable/dataTables.select.min.js') }}"></script>

Datatable config to add in datatable_config.blade.php setting for multiselect (the column 0, will have a the icon already and will be the cell that trigger the select action. So personnaly, I used the check colum type and removed the content since the class select-checkbox add already the icon :

'columnDefs': [ {
  'orderable': false,
  'targets':   0,
  'className': 'select-checkbox',
   'targets': 0,
} ],
  'select': {
   'info': true,
   'style':    'multi',/*os for single selection*/
   'selector': 'td:first-child'
}

Are there any updates regarding this feature? How to define the custom actions using what @mamarmite suggests?

BOOM! Bulk buttons are almost here - finally been able to make this a priority :-)

If you have time, please check out this PR and let me know what you think.

Cheers!

Was this page helpful?
0 / 5 - 0 ratings