z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.13k stars 2.81k forks source link

How do I add a new method to Encore\Admin\Grid\Column ? #5860

Open jicksonjohnson opened 2 months ago

jicksonjohnson commented 2 months ago

Description:

I am trying to add a new column filter. To achieve this, I need to place a new method similar to "filter" that exists in "Encore\Admin\Grid\Column". Since this is part of a vendor package, I cannot edit it directly. Therefore, my plan is to rewrite this vendor class. I tried using the following code in "AdminServiceProvider". This is a new ServiceProvider I added under config/app.php to make this change.

public function boot() { Admin::booting(function () { $this->app->singleton(\Encore\Admin\Grid\Column::class, \App\Admin\Extensions\Override\Grid\Column::class); }); }

Here my try is to rewrite vendor class method "filter"

`<?php

namespace App\Admin\Extensions\Override\Grid;

use Encore\Admin\Grid\Column as OriginalColumn;

class Column extends OriginalColumn { /**

I do not see this change reflected. Could someone help me with rewriting this vendor class?

jicksonjohnson commented 2 months ago

I need to keep the column filter open, like below

Screenshot 2024-07-09 at 5 51 20 PM

I did this by editing the vendor files.

  1. Edited "Encore\Admin\Grid\Column" class by adding new method called "open_filter"

`/**

If anyone knows of a better approach to accomplish this without editing the vendor files, please advise.