How to use expander to update the data in atk4 grid?

233 Views Asked by At

Let's say I created a model "product" with a few fields such as "name", "price","tax","shipping" etc.

At first I just want to show name and price in the grid:

$g = $this->add('MVCGrid')
$g -> setModel('product', array('name','price'));

Then I would like to add a column of expander button called "sold" to update the "tax" and "shipping" for that product:

$g -> addColumn('expander','sold');

In the sold.php file, I put:

$f = $this -> add('MVCForm');
$f -> setModel('product',array('tax','shipping'));
$f -> addSubmit()-> setLabel('Update');

My question is how to get the id of the product I am trying to update in the expander page? i.e. what kind of code should I put in the

if($f->isSubmitted()){

}

in order to update the tax and shipping of the product which I clicked the "sold" expander button on?


BTW: is there any way that I can close the expander after I hit the submit button?

1

There are 1 best solutions below

3
On

Expander passes the id through several GET variables:

  • id
  • tablename_id (calculated based on model->entity_code

Using 'id' is handy, but the second method is handier if you are doing nesting expanders. Don't forget to use stickyGET().