RS
Lista de seleção de registo filtro não funciona
Lista não funciona os filtros, não faz nada, digitei numero mas traz todos.
- <?php
- /**
- * AgetranVagaIdosoSelectionList Record selection
- * @author <your name here>
- */
- class AgetranVagaIdosoSelectionList extends TPage
- {
- protected $form; // search form
- protected $datagrid; // listing
- protected $pageNavigation;
- use Adianti\base\AdiantiStandardListTrait;
- /**
- * Page constructor
- */
- public function __construct()
- {
- parent::__construct();
- $this->setDatabase('dmdbd'); // defines the database
- $this->setActiveRecord('AgetranVagaIdoso'); // defines the active record
- $this->setDefaultOrder('id', 'desc'); // defines the default order
- // $this->setCriteria($criteria) // define a standard filter
- $this->addFilterField('id', '=', 'form_id'); // filterField, operator, formField
- $this->addFilterField('id_idoso', '=', 'id_idoso'); // filterField, operator, formField
- $this->addFilterField('emissao', '=', 'emissao', function($value) {
- return TDate::convertToMask($value, 'dd/mm/yyyy', 'yyyy-mm-dd');
- }); // filterField, operator, formField, transformFunction
- // creates the form
- $this->form = new BootstrapFormBuilder('form_search_AgetranVagaIdoso');
- $this->form->setFormTitle('Selecionar Credências Idoso para Impressão');
- // create the form fields
- $form_id = new TEntry('form_id');
- $id_idoso = new TEntry('id_idoso');
- $emissao = new TDate('emissao');
- $emissao->setValue(date('d/m/Y'));
- // add the fields
- $this->form->addFields( [ new TLabel('Número') ], [ $form_id ] );
- $this->form->addFields( [ new TLabel('Nome') ], [ $id_idoso ] );
- $this->form->addFields( [ new TLabel('Emissão') ], [ $emissao ] );
- // set sizes
- $form_id->setSize('10%');
- $id_idoso->setSize('70%');
- $emissao->setSize('10%');
- $emissao->setMask('dd/mm/YYYY');
- $emissao->setOption('triggerEvent', 'dblclick');
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('AgetranVagaIdoso_filter_data') );
- $btn = $this->form->addAction(_t('Find'), new TAction([$this, 'onSearch']), 'fa:search');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addAction('Show results', new TAction([$this, 'showResults']), 'fa:check-circle-o green');
- // creates a DataGrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'Número', 'right');
- $column_id_idoso = new TDataGridColumn('idoso->nome', 'Nome', 'left');
- $column_emissao = new TDataGridColumn('emissao', 'Emissão', 'left');
- $column_uf = new TDataGridColumn('uf', 'UF', 'left');
- $column_cidade = new TDataGridColumn('cidade', 'Cidade', 'left');
- $column_orgao_expedidor = new TDataGridColumn('orgao_expedidor', 'Orgao Expedidor', 'left');
- $column_validade = new TDataGridColumn('validade', 'Validade', 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_id_idoso);
- $this->datagrid->addColumn($column_emissao);
- $this->datagrid->addColumn($column_uf);
- $this->datagrid->addColumn($column_cidade);
- $this->datagrid->addColumn($column_orgao_expedidor);
- $this->datagrid->addColumn($column_validade);
- $column_emissao->setTransformer( function($value, $object, $row) {
- $date = new DateTime($value);
- return $date->format('d/m/Y');
- });
- $column_validade->setTransformer( function($value, $object, $row) {
- $date = new DateTime($value);
- return $date->format('d/m/Y');
- });
- // creates the datagrid column actions
- $column_id->setAction(new TAction([$this, 'onReload']), ['order' => 'id']);
- $column_emissao->setAction(new TAction([$this, 'onReload']), ['order' => 'emissao']);
- $column_id->setTransformer([$this, 'formatRow'] );
- // creates the datagrid actions
- $action1 = new TDataGridAction([$this, 'onSelect']);
- $action1->setUseButton(TRUE);
- $action1->setButtonClass('btn btn-default');
- $action1->setLabel(AdiantiCoreTranslator::translate('Select'));
- $action1->setImage('fa:check-circle-o blue');
- $action1->setField('id');
- // add the actions to the datagrid
- $this->datagrid->addAction($action1);
- // create the datagrid model
- $this->datagrid->createModel();
- // create the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
- parent::add($container);
- }
- /**
- * Save the object reference in session
- */
- public function onSelect($param)
- {
- // get the selected objects from session
- $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
- TTransaction::open('dmdbd');
- $object = new AgetranVagaIdoso($param['key']); // load the object
- if (isset($selected_objects[$object->id]))
- {
- unset($selected_objects[$object->id]);
- }
- else
- {
- $selected_objects[$object->id] = $object->toArray(); // add the object inside the array
- }
- TSession::setValue(__CLASS__.'_selected_objects', $selected_objects); // put the array back to the session
- TTransaction::close();
- // reload datagrids
- $this->onReload( func_get_arg(0) );
- }
- /**
- * Highlight the selected rows
- */
- public function formatRow($value, $object, $row)
- {
- $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
- if ($selected_objects)
- {
- if (in_array( (int) $value, array_keys( $selected_objects ) ) )
- {
- $row->style = "background: #FFD965";
- }
- }
- return $value;
- }
- /**
- * Show selected records
- */
- public function showResults()
- {
- $datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
- $datagrid->addQuickColumn('Número', 'id', 'right');
- $datagrid->addQuickColumn('Nome', 'id_idoso', 'left');
- $datagrid->addQuickColumn('Emissão', 'emissao', 'left');
- $datagrid->addQuickColumn('UF', 'uf', 'left');
- $datagrid->addQuickColumn('Cidade', 'cidade', 'left');
- $datagrid->addQuickColumn('Orgao Expedidor', 'orgao_expedidor', 'left');
- $datagrid->addQuickColumn('Validade', 'validade', 'left');
- // create the datagrid model
- $datagrid->createModel();
- $selected_objects = TSession::getValue(__CLASS__.'_selected_objects');
- ksort($selected_objects);
- if ($selected_objects)
- {
- $datagrid->clear();
- foreach ($selected_objects as $selected_object)
- {
- $datagrid->addItem( (object) $selected_object );
- }
- }
- $win = TWindow::create('Results', 0.6, 0.6);
- $win->add($datagrid);
- $win->show();
- }
- }
- ?>
Vou tentar achar algo.
achei o problema mudei de: TPage para TStandardList e funcionou