webelizer
webelizer

Reputation: 418

Showing a lister when grid button clicked? (in Agile Toolkit)

I have a grid that have buttons in one of it's columns like this: how can I show a lister or a new grid when the button clicked?

   $grid=$page->add('Grid');
        $grid->setModel('Tickets',array('subject','date','time','department','status','text'));
        $grid->addColumn("button",'read_ticket_id','Read');

        if($_GET['read_ticket_id']){
            // this generates javascript to be executed on buttion click
       //how can I show a lister or a new grid when the button clicked?
        }

Upvotes: 1

Views: 636

Answers (2)

webelizer
webelizer

Reputation: 418

I found a good example for this question:

http://agiletoolkit.org/doc/grid/interaction

==========

$g=$p->add('Grid');
$g->setSource('user');
$g->addColumn('name');
$g->addColumn('surname');
$g->addColumn('button','info','More Info');
$g->dq->where('name is not null')->limit(5);

if($_GET['info']){
    $g->js()->univ()->dialogURL('More info',
            $this->api->getDestinationURL(
                null,array(
                    'more_info'=>$_GET['info'],
                    'cut_object'=>'myform'
                    )))
        ->execute();
}

if($_GET['more_info']){
    $f=$this->add('Form','myform');
    $f->addField('readonly','name');
    $f->addField('readonly','surname');
    $f->setSource('user');
    $f->setConditionFromGET('id','more_info');
}

Upvotes: 1

DarkSide
DarkSide

Reputation: 3709

Check out examples in ATK4 Codepad. http://agiletoolkit.org/codepad/gui/grid

Edit: This is snippet from one of my pages. Maybe you can find it useful. The idea behind this is that you actually generate JavaScript inside this IF statement and JavaScript then is sent back to your browser which then can make another request for something (reload existing object, create new, redirect to somewhere etc.)

...
if($_GET['ticket']){
    // Join this report with selected ticket
    $this->grid->model->addToTicket($_GET['ticket']);
    // Reload
    $this->js(null,array(
        $x->js()->reload(),
        $this->js()->univ()->successMessage('Successfully saved')
    ))->execute();
}
...

With $_GET['ticket'] you get ID of record in grid in which you clicked button "Add to Ticket". $x is some other object in this page, for example, some form, field, tab or other grid. With $this->grid->model you get reference to model associated with this grid and in that model I have custom action/method defined - addToTicket which do something with database.

You can also redirect to other page with $this->js()->redirect() or $this->js()->location() etc. Basically you can do whatever you want, but all of this need to generate JavaScript as result or instructions for your browser what to do next.

And don't forget to add ->execute() at the end! That will stop further parsing your page and will instantly generate JS response.

Upvotes: 1

Related Questions