Reload grid after dropdown selection.

60 views
Skip to first unread message

Marty

unread,
Apr 16, 2014, 3:48:29 AM4/16/14
to agile-too...@googlegroups.com
I'v setup a many to many relation with intermediate table.
It is used to create/view watchlists for funds.
ATK4.2.5

But now I'd like to create a drowpdown with watchlists, add the condition to the model and automaticaly reload the grid. Didn't find a "simple" example so far searching docs, questions or demos.. Again it must be easy... but somehow I've been trying for few hours without result.

class Model_FundWatchlist extends Model_Table {
public $table="fundwatchlist";
function init(){
parent::init();

$this->hasOne('Watchlist');
$this->hasOne('Fund');
//$this->addCondition('watchlist_id',1);

}

class page_fundwatchlist extends Page {
function init(){
parent::init();
//debug
//$this->add('Text')->set(json_encode($_GET));
$f = $this->add('Form');
$wl = $f->addField('dropdown','watchlist','Watchlist')
->setEmptyText('Select a list');
$wl->setModel('Watchlist');
$wl->js('change', $f->js()->trigger('submit'));

$c = $this->add('CRUD',array('allow_add'=>true,
'allow_edit'=>true,
'allow_delete'=>true,
'frame_options'=>array('width'=>'600px')));
$c->setModel('Fundwatchlist');
//on change dropbox add $c->addCondition('watchlist_id',$_GET['watchlist_id']);

if ($c->grid) {
            $c->grid->addQuickSearch(array('fund'));
$c->grid->addPaginator(25);
}
}
}

Janis Volbergs

unread,
Apr 16, 2014, 3:55:02 AM4/16/14
to agile-too...@googlegroups.com
Hi,


On 16 Apr 2014, at 10:48, Marty <app...@gmail.com> wrote:

> I'v setup a many to many relation with intermediate table.
> It is used to create/view watchlists for funds.
> ATK4.2.5
>
> But now I'd like to create a drowpdown with watchlists, add the condition to the model and automaticaly reload the grid. Didn't find a "simple" example so far searching docs, questions or demos.. Again it must be easy... but somehow I've been trying for few hours without result.
>
> class Model_FundWatchlist extends Model_Table {
> public $table="fundwatchlist";
> function init(){
> parent::init();
>
> $this->hasOne('Watchlist');
> $this->hasOne('Fund');
> //$this->addCondition('watchlist_id',1);
>
> }
> }
>
> class page_fundwatchlist extends Page {
> function init(){
> parent::init();
> //debug
> //$this->add('Text')->set(json_encode($_GET));
>
> $f = $this->add('Form');
> $wl = $f->addField('dropdown','watchlist','Watchlist')
> ->setEmptyText('Select a list');
> $wl->setModel('Watchlist');
> $wl->js('change', $f->js()->trigger('submit'));

you can also do: $f->js()->submit();


>
> $c = $this->add('CRUD',array('allow_add'=>true,
> 'allow_edit'=>true,
> 'allow_delete'=>true,
> 'frame_options'=>array('width'=>'600px')));
> $c->setModel('Fundwatchlist');
> //on change dropbox add $c->addCondition('watchlist_id',$_GET['watchlist_id']);
>
> if ($c->grid) {
> $c->grid->addQuickSearch(array('fund'));
> $c->grid->addPaginator(25);
> }
>
> }
> }


I don’t see where you are handling the form submit and grid reload.

YOu should have something like (after adding paginator):

if ($f->isSubmitted()){
$c->dq->where(“fund_id”, $f->get(“watchlist”));
$c->js()->reload()->execute();
}

Marty

unread,
Apr 16, 2014, 3:43:00 PM4/16/14
to agile-too...@googlegroups.com, j...@agiletech.ie
Hi Janis, Thanks for your reply.

I have changed the code but where clause is not added to query on submit.. 
Updated atk4 to latest git.

class page_fundwatchlist extends Page {
function init(){
parent::init();
//debug
$this->add('Text')->set(json_encode($_GET));

$f = $this->add('Form');
$watchlist = $f->addField('dropdown','watchlist','Watchlist')
->setEmptyText('Select a list');
$watchlist->setModel('Watchlist');
$watchlist->js('change', $f->js()->submit());
$c = $this->add('CRUD',array('allow_add'=>true,
'allow_edit'=>true,
'allow_delete'=>true,
'frame_options'=>array('width'=>'600px')));
$c->setModel('Fundwatchlist')->Debug();
if ($c->grid) {
            $c->grid->addQuickSearch(array('fund','watchlist'));
$c->grid->addPaginator(25);
}

// $c->dq->where('watchlist_id', 1); //works

if ($f->isSubmitted()){ 
        //$c->dq->where('watchlist_id', $f->get('watchlist'));
        $c->dq->where('watchlist_id', 1); //does not work
        $c->js()->reload()->execute(); 
}
}


if ($f->isSubmitted()){ 
        //$c->dq->where('watchlist_id', $f->get('watchlist'));
        $c->dq->where('watchlist_id', 1); //does not work
        $c->js()->reload()->execute(); 
Query:
select SQL_CALC_FOUND_ROWS (select `name` from `watchlist` where `fundwatchlist`.`watchlist_id` = `watchlist`.`id` ) `watchlist`,(select `name` from `Fund` where `fundwatchlist`.`Fund_id` = `Fund`.`id` ) `Fund`,`id`,`watchlist_id`,`Fund_id` from `fundwatchlist` limit 0, 25 []

Query when using $c->dq->where('watchlist_id', 1); (for testing) outside if ($f->isSubmitted()){ 
select SQL_CALC_FOUND_ROWS (select `name` from `watchlist` where `fundwatchlist`.`watchlist_id` = `watchlist`.`id` ) `watchlist`,(select `name` from `Fund` where `fundwatchlist`.`Fund_id` = `Fund`.`id` ) `Fund`,`id`,`watchlist_id`,`Fund_id` from `fundwatchlist` where `watchlist_id` = 1 limit 0, 25 [:a]

Somehow when clause is not added using isSubmitted?

Marty

unread,
Apr 17, 2014, 4:23:11 AM4/17/14
to agile-too...@googlegroups.com
Hi Janis, 
Works like a charm , thank for your patience.

class page_fundwatchlist extends Page {
function init(){
parent::init();
//debug
$this->add('Text')->set(json_encode($_GET));

$f = $this->add('Form');
$watchlist = $f->addField('dropdown','watchlist','Watchlist')
->setEmptyText('Select a list');
$watchlist->setModel('Watchlist');
$watchlist->js('change', $f->js()->submit());
$c = $this->add('CRUD',array('allow_add'=>true,
'allow_edit'=>true,
'allow_delete'=>true,
'frame_options'=>array('width'=>'600px')));
$c->setModel('Fundwatchlist')->Debug();
if ($c->grid) {
                     $c->grid->addQuickSearch(array('fund','watchlist'));
     $c->grid->addPaginator(25);
}

if ($f->isSubmitted()){ 
            $this->memorize('watchlist_id', $f->get('watchlist'));
            $c->js()->reload()->execute(); 

if ($id=$this->recall('watchlist_id')){
$c->dq->where('watchlist_id', $id);
}
}
}
Reply all
Reply to author
Forward
0 new messages