leantony / laravel-grid

A grid view for laravel, inspired by the yii2 grid widget
https://leantony.github.io/laravel-grid/
MIT License
91 stars 39 forks source link

Issue: an error "Undefined index: Edit" occurs when making custom row button #85

Open ratbek opened 5 years ago

ratbek commented 5 years ago

I wrote a code to make custom row button below:

public function configureButtons()
    {
        $this->makeCustomButton([
            'name' => 'Edit',
            'icon' => 'fa-eye',
            'position' => 1,
            'class' => 'btn btn-outline-primary btn-sm grid-row-button',
            'showModal' => false,
            'gridId' => $this->getId(),
            'title' => 'edit record',
            'url' => function() {
                return route('abacus.edit');
            },
        ], static::$TYPE_ROW);
    }

But I got an error "Undefined index: Edit" in makeCustomButton() function

protected function makeCustomButton(array $properties, $position = null): GenericButton
    {
        $key = $properties['name'] ?? 'unknown';
        $position = $position ?? static::$TYPE_TOOLBAR;
        if ($position === static::$TYPE_TOOLBAR) {
            $this->addToolbarButton($key, new GenericButton(array_merge($properties, ['type' => $position])));
        } else {
            $this->addRowButton($key, new GenericButton(array_merge($properties, ['type' => $position])));
        }

        return $this->buttons[$position][$key]; // <--- here an error occurs, undefined $key
    }

Also I added "Edit" to $buttonsToGenerate field

protected $buttonsToGenerate = [
        'create',
        'view',
        'edit', // <-- here
        'delete',
        'refresh',
    ];
leantony commented 5 years ago

Remove the 'edit' key from the $buttonsToGenerate array

On Wed, Sep 19, 2018 at 11:27 AM ratbek notifications@github.com wrote:

I wrote a code to make custom row button below:

public function configureButtons() { $this->makeCustomButton([ 'name' => 'Edit', 'icon' => 'fa-eye', 'position' => 1, 'class' => 'btn btn-outline-primary btn-sm grid-row-button', 'showModal' => false, 'gridId' => $this->getId(), 'title' => 'edit record', 'url' => function() { return route('abacus.edit'); }, ], static::$TYPE_ROW); }

But I got an error "Undefined index: Edit" in makeCustomButton() function

protected function makeCustomButton(array $properties, $position = null): GenericButton { $key = $properties['name'] ?? 'unknown'; $position = $position ?? static::$TYPE_TOOLBAR; if ($position === static::$TYPE_TOOLBAR) { $this->addToolbarButton($key, new GenericButton(array_merge($properties, ['type' => $position]))); } else { $this->addRowButton($key, new GenericButton(array_merge($properties, ['type' => $position]))); }

    return $this->buttons[$position][$key]; // <--- here an error occurs, undefined $key
}

Also I added "Edit" to $buttonsToGenerate field

protected $buttonsToGenerate = [ 'create', 'view', 'edit', // <-- here 'delete', 'refresh', ];

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/leantony/laravel-grid/issues/85, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmSKNQepdyhWEJHFEKAva0KaY3gAJM4ks5ucgAGgaJpZM4WvqZz .

leantony commented 5 years ago

https://github.com/leantony/laravel-grid/blob/master/docs/buttons.md#adding-buttons-with-urls-dependent-on-the-data-items https://github.com/leantony/laravel-grid/blob/master/docs/buttons.md#adding-custom-buttons

On Thu, Sep 20, 2018 at 10:36 AM Antony Chacha chachaantony@gmail.com wrote:

Remove the 'edit' key from the $buttonsToGenerate array

On Wed, Sep 19, 2018 at 11:27 AM ratbek notifications@github.com wrote:

I wrote a code to make custom row button below:

public function configureButtons() { $this->makeCustomButton([ 'name' => 'Edit', 'icon' => 'fa-eye', 'position' => 1, 'class' => 'btn btn-outline-primary btn-sm grid-row-button', 'showModal' => false, 'gridId' => $this->getId(), 'title' => 'edit record', 'url' => function() { return route('abacus.edit'); }, ], static::$TYPE_ROW); }

But I got an error "Undefined index: Edit" in makeCustomButton() function

protected function makeCustomButton(array $properties, $position = null): GenericButton { $key = $properties['name'] ?? 'unknown'; $position = $position ?? static::$TYPE_TOOLBAR; if ($position === static::$TYPE_TOOLBAR) { $this->addToolbarButton($key, new GenericButton(array_merge($properties, ['type' => $position]))); } else { $this->addRowButton($key, new GenericButton(array_merge($properties, ['type' => $position]))); }

    return $this->buttons[$position][$key]; // <--- here an error occurs, undefined $key
}

Also I added "Edit" to $buttonsToGenerate field

protected $buttonsToGenerate = [ 'create', 'view', 'edit', // <-- here 'delete', 'refresh', ];

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/leantony/laravel-grid/issues/85, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmSKNQepdyhWEJHFEKAva0KaY3gAJM4ks5ucgAGgaJpZM4WvqZz .

ratbek commented 5 years ago

I tried to remove, but it still doesn't work.

tgatev commented 5 years ago

I tried to remove, but it still doesn't work.

Hi ratbek, if you still have interest, you should define rednderIf property of the button as callback

shahidiqbal12 commented 4 years ago

I tried to remove, but it still doesn't work.

Hi ratbek, Did you resolve this issue? I'm also facing the same.

ratbek commented 4 years ago

Hi shahidiqbal12. No, I didn't. At the moment, I don't use this grid view.

shahidiqbal12 commented 4 years ago

Hi shahidiqbal12. No, I didn't. At the moment, I don't use this grid view.

Thanks @ratbek