I want to control a grid with dates on two DatePickers, I'm reloading the whole page, although it may be better to reload the grid only. Anyway, I can't get the value of the datepicker in order to use it in the array in the reload, how should I do that? I have this:
class page_caja extends Page {
function init(){
parent::init();
if(!$_GET['fInicial']){
$fInicial=date('d/m/Y');
}else{
$fInicial=$_GET['fInicial'];
}
if(!$_GET['fFinal']){
$fFinal=date('d/m/Y');
}else{
$fFinal=$_GET['fFinal'];
}
$f=$this->add('Form');
$inicial=$f->addField('DatePicker','fInicial','Fecha Incial')->set($fInicial);
$final=$f->addField('DatePicker','fFinal','Fecha Final')->set($fFinal);
//Tabla de Pagos Pendientes
$this->add('H3')->set('Movimientos');
$g=$this->add('MVCGrid');
$g->setModel('Caja');
$g->removeColumn('programaPago');
$g->addColumn('date','created_dts','Fecha');
$g->dq->where("DATE(created_dts)>=",$inicial->get());
$g->dq->where("DATE(created_dts)<=",$final->get());
$g->addTotals();
$inicial->js('change',$this->js()->reload(array('fInicial'=>$inicial->js()->value(),'fFinal'=>$final->js()->value())));
$final->js('change',$this->js()->reload(array('fInicial'=>$inicial->js()->value(),'fFinal'=>$final->js()->value())));
}
}
Your approach is quite good, I don't see anything wrong with it, although I would write it like this. My method uses filter submit and takes one extra reload, but it works quite smooth and simple to understand:
$filter = $page->add('Form');
$grid = $page->add('Grid')->setModel('Caja');
$filter->addField('date','d1')->js('change',$filter->js()->submit());
$filter->addField('date','d2')->js('change',$filter->js()->submit());
if($filter->isSubmited()){z
$this->memorize('d1',$filter->get('d1'));
$this->memorize('d2',$filter->get('d2'));
$grid->js()->reload()->execute();
}
$d1=$this->recall('d1',null);
if($d1)$grid->dq->where('date(created_dts)>=',$d1);
$d1=$this->recall('d2',null);
if($d2)$grid->dq->where('date(created_dts)<=',$d2);
You can also incorporate fields into the reload() but then you should be reading $d1 and $d2 from $_GET variable.
If you can't get value from a field, try simpler ways:
$form->addField('test')->js('change')
->univ()->log(
$form->getElement('test')->js()->val()
);
Then watch Inspector's Console for output.