admin icon indicating copy to clipboard operation
admin copied to clipboard

Mass deleting

Open alexander-zugan opened this issue 9 years ago • 8 comments

How can i make Mass removal in Admin Panel ??

alexander-zugan avatar Aug 10 '15 08:08 alexander-zugan

Hi,

this is very easy to implement.

For V.3 use this: http://sleeping-owl.github.io/v3/en/Displays.html --> Bulk Actions

What you have to do is the following:

  • Add the Column::checkbox() to your display columns. Something like this:
  • Add the following also inside your display() function
$display->actions([
    Column::action('export')->value('Export')->icon('fa-share')->target('_blank')->callback(function ($collection)
    {
        dd('You are trying to export:', $collection->toArray());
    }),
    ...
]);

This is the example from the documentation, you have to change it to whatever you need...

Here is a short example:

Admin::model('App\Model')->title('Title')->display(function ()
{
    $display = AdminDisplay::datatables();

    $display->columns([
        Column::checkbox(),
        Column::string('id')->label('#'),
        //some other columns
    ]);


    $display->actions([
        Column::action('massdelete')->value('Massdelete')->icon('fa-trash')->callback(function ($collection)
        {
            foreach ($collection->toArray() as $key => $delete_item) {

                $item = App\Model::find($delete_item['id']);
                //http://laravel.com/docs/5.1/eloquent#deleting-models
                $item->delete();
            }
        }),
        //more actions
    ]);

    return $display;
}   

Hope this helps :)

noxify avatar Aug 10 '15 09:08 noxify

Thanks ,but i use v2 ... It is possible to make for v2 ??

alexander-zugan avatar Aug 10 '15 10:08 alexander-zugan

I don't know - but I didn't see any in the V2 documentation. Maybe @sleeping-owl can say something?

Otherwise - upgrade to V.3 :)

noxify avatar Aug 10 '15 10:08 noxify

I very late saw the v3 version and now only on the following project I will use v3 . But now it is necessary to think up something for v2 ...

alexander-zugan avatar Aug 10 '15 10:08 alexander-zugan

Maybe you can add the actions() function to v2: https://github.com/sleeping-owl/admin/blob/development/src/SleepingOwl/Admin/Display/DisplayTable.php#L192

I didn't work with V.2, don't know where to implement it in V.2 - sorry :(

noxify avatar Aug 10 '15 11:08 noxify

V.2 has no Column::checkbox() ((

alexander-zugan avatar Aug 10 '15 16:08 alexander-zugan

In current (latest) version displays functionality is missing. Is there any way to perform bulk operations?

theravel avatar Aug 18 '16 11:08 theravel

Вот так можно $display->setActions([ AdminColumn::action('delete', ' Удалить')->setIcon('fa fa-share')->setAction(route('admin_massdelete'))->useGet(), ])

Ну, а в контроллер по указаному роуту, уже делаешь уделание или что тебе нужно

alexander-zugan avatar Aug 18 '16 12:08 alexander-zugan