1

There is a custom button class (extends from Encore\Admin\Actions\RowAction).

The class has a confirmation window with unique information for each row.

    / **
     * @return void
     * /
    public function dialog()
    {
        $model = Categories::where('id',$this->getKey())->with('users')->get();
        $this->question(trans('admin.delete_confirm'), 'Comment:'.$model[0]->comment, ['confirmButtonColor' => '#d33']);
    }

When scripts are formed to invoke a dialog, they have the same class identifier (for example, ".grid-row-action-5dca9548c28226038"), but different text.

...
$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 1",
...
}

$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 2",
...
}

$ ('.grid-row-action-5dca9548c28226038').off('click').on('click', function() {
...
"text": "Comment: text 3",
...
}
...

How to make Laravel admin generate a unique identifier for each line?

devAston
  • 63
  • 10

2 Answers2

0

The solution was to override the method to get the selector.

    /**
     * @var bool
     */
    protected $multiplePrefix = true;

...

    /**
     * @param string $prefix
     *
     * @return mixed|string
     */
    public function selector($prefix)
    {
        if (isset($this->multiplePrefix)){
            return $this->getOptionalPrefix($prefix);
        } elseif (is_null($this->selector)) {
            return static::makeSelector(get_called_class(), $prefix);
        }

        return $this->selector;
    }

    /**
     * @param $prefix
     * @return string
     */
    protected function getOptionalPrefix($prefix)
    {
        if (is_null($this->selector)) {
            $this->selector = uniqid($prefix) . mt_rand(1000, 9999);
        }
        return $this->selector;
    }
devAston
  • 63
  • 10
0
$grid->disableRowSelector();
sa-es-ir
  • 3,722
  • 2
  • 13
  • 31
MUHINDO
  • 788
  • 6
  • 10