CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

afterColumn() doesn't work from custom trait.

Open karandatwani92 opened this issue 10 months ago • 0 comments

Discussed in https://github.com/Laravel-Backpack/community-forum/discussions/904

Originally posted by cdo9 March 29, 2024 Hello, this is my "setupHasStatusDefaults" function code from my "HasStatusOperation" trait :

$this->crud->operation('list', function () {
    $this->crud->addColumn([
        'name' => 'status',
        'label' => 'status',
        'type' => 'enum',
    ])->afterColumn('id');
});

The column is added, but before any column (first one). Maybe because the HasStatusOperation is loaded before the setupListOperation ? Is there a way to do it after ? I would love to make operations like that to add columns/filters/fields to CRUDs that need it.

EDIT : for now I added ->makeFirst(); to my ID column, so this does the trick to put the field in 2nd

Hey @pxpm

Please take a look at the details in the above discussion.

I tested it and the user is right. I also thought the list closure runs in the setup() before setupListOperation, so I removed setupListOperation() and moved columns in the list closure inside setup() of CRUD. Still the same result.

Apart from this, I also found:

  • CRUD::addColumn('number')->afterColumn('series'); works ✅
  • CRUD::column('number')->afterColumn('series'); - This adds column but afterColumn() doesn't works.❌

karandatwani92 avatar Apr 15 '24 11:04 karandatwani92