Atk4 UI: callback/modal on table cell click

94 views Asked by At

What is the best way to attach:

a) PHP callback
b) Open a modal

to a table created like this:

$table = $app->add(['Table', 'celled' => true]);
$table->setModel($mod, false);
$table->addColumn('name');

?

I tried some examples from doc, but they were not for the Table component, but for Grid and the usage seems to be very different.

2

There are 2 answers

0
DarkSide On

I think you better use Grid class. It will have more options and extensions than Table. Table is meant for simple reporting purposes or things like that. For interactive tables - use Grid or CRUD.

0
romaninsh On

Grid is a View which contains table, menu and paginator. To set callback on any view use:

$table->on('.class-or-selector', function(..) { });

You may also pass arguments:

$table->on('.class-or-selector', function($j, $arg1, $arg2) {}, [
    new jsExpression('..'), // passed along as $arg1
    new jsExpression('..'), // passed as $arg2
]);

As example, you can use Table's jsRow() function to reference clicked row and fetch "ID":

$jsexpr1 = $table->jsRow()->data('id');