Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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. ...
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.

  1. <?php
  2. /**
  3.  * AgetranVagaIdosoSelectionList Record selection
  4.  * @author  <your name here>
  5.  */
  6. class AgetranVagaIdosoSelectionList extends TPage
  7. {
  8.     protected $form;     // search form
  9.     protected $datagrid// listing
  10.     protected $pageNavigation;
  11.     
  12.     use Adianti\base\AdiantiStandardListTrait;
  13.     
  14.     /**
  15.      * Page constructor
  16.      */
  17.     public function __construct()
  18.     {
  19.         parent::__construct();
  20.         
  21.         $this->setDatabase('dmdbd');            // defines the database
  22.         $this->setActiveRecord('AgetranVagaIdoso');   // defines the active record
  23.         $this->setDefaultOrder('id''desc');         // defines the default order
  24.         // $this->setCriteria($criteria) // define a standard filter
  25.         $this->addFilterField('id''=''form_id'); // filterField, operator, formField
  26.         $this->addFilterField('id_idoso''=''id_idoso'); // filterField, operator, formField
  27.         $this->addFilterField('emissao''=''emissao', function($value) {
  28.             return TDate::convertToMask($value'dd/mm/yyyy''yyyy-mm-dd');
  29.         }); // filterField, operator, formField, transformFunction
  30.         
  31.         // creates the form
  32.         $this->form = new BootstrapFormBuilder('form_search_AgetranVagaIdoso');
  33.         $this->form->setFormTitle('Selecionar Credências Idoso para Impressão');
  34.         
  35.         // create the form fields
  36.         $form_id = new TEntry('form_id');
  37.         $id_idoso = new TEntry('id_idoso');
  38.         $emissao = new TDate('emissao');
  39.         $emissao->setValue(date('d/m/Y'));
  40.         // add the fields
  41.         $this->form->addFields( [ new TLabel('Número') ], [ $form_id ] );
  42.         $this->form->addFields( [ new TLabel('Nome') ], [ $id_idoso ] );
  43.         $this->form->addFields( [ new TLabel('Emissão') ], [ $emissao ] );
  44.         // set sizes
  45.         $form_id->setSize('10%');
  46.         $id_idoso->setSize('70%');
  47.         $emissao->setSize('10%');
  48.         $emissao->setMask('dd/mm/YYYY');
  49.         $emissao->setOption('triggerEvent''dblclick');
  50.         // keep the form filled during navigation with session data
  51.         $this->form->setDataTSession::getValue('AgetranVagaIdoso_filter_data') );
  52.         
  53.         $btn $this->form->addAction(_t('Find'), new TAction([$this'onSearch']), 'fa:search');
  54.         $btn->class 'btn btn-sm btn-primary';
  55.         $this->form->addAction('Show results', new TAction([$this'showResults']), 'fa:check-circle-o green');
  56.         
  57.         // creates a DataGrid
  58.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  59.         $this->datagrid->style 'width: 100%';
  60.         $this->datagrid->datatable 'true';
  61.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  62.         
  63.         // creates the datagrid columns
  64.         $column_id = new TDataGridColumn('id''Número''right');
  65.         $column_id_idoso = new TDataGridColumn('idoso->nome''Nome''left');
  66.         $column_emissao = new TDataGridColumn('emissao''Emissão''left');
  67.         $column_uf = new TDataGridColumn('uf''UF''left');
  68.         $column_cidade = new TDataGridColumn('cidade''Cidade''left');
  69.         $column_orgao_expedidor = new TDataGridColumn('orgao_expedidor''Orgao Expedidor''left');
  70.         $column_validade = new TDataGridColumn('validade''Validade''left');
  71.         // add the columns to the DataGrid
  72.         $this->datagrid->addColumn($column_id);
  73.         $this->datagrid->addColumn($column_id_idoso);
  74.         $this->datagrid->addColumn($column_emissao);
  75.         $this->datagrid->addColumn($column_uf);
  76.         $this->datagrid->addColumn($column_cidade);
  77.         $this->datagrid->addColumn($column_orgao_expedidor);
  78.         $this->datagrid->addColumn($column_validade);
  79.         $column_emissao->setTransformer( function($value$object$row) {
  80.             $date = new DateTime($value);
  81.             return $date->format('d/m/Y');
  82.         });
  83.          $column_validade->setTransformer( function($value$object$row) {
  84.             $date = new DateTime($value);
  85.             return $date->format('d/m/Y');
  86.         });
  87.         
  88.         // creates the datagrid column actions
  89.         $column_id->setAction(new TAction([$this'onReload']), ['order' => 'id']);
  90.         $column_emissao->setAction(new TAction([$this'onReload']), ['order' => 'emissao']);
  91.         $column_id->setTransformer([$this'formatRow'] );
  92.         
  93.         // creates the datagrid actions
  94.         $action1 = new TDataGridAction([$this'onSelect']);
  95.         $action1->setUseButton(TRUE);
  96.         $action1->setButtonClass('btn btn-default');
  97.         $action1->setLabel(AdiantiCoreTranslator::translate('Select'));
  98.         $action1->setImage('fa:check-circle-o blue');
  99.         $action1->setField('id');
  100.         
  101.         // add the actions to the datagrid
  102.         $this->datagrid->addAction($action1);
  103.         
  104.         // create the datagrid model
  105.         $this->datagrid->createModel();
  106.         
  107.         // create the page navigation
  108.         $this->pageNavigation = new TPageNavigation;
  109.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  110.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  111.         
  112.         // vertical box container
  113.         $container = new TVBox;
  114.         $container->style 'width: 90%';
  115.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  116.         $container->add($this->form);
  117.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  118.         
  119.         parent::add($container);
  120.     }
  121.     
  122.     /**
  123.      * Save the object reference in session
  124.      */
  125.     public function onSelect($param)
  126.     {
  127.         // get the selected objects from session 
  128.         $selected_objects TSession::getValue(__CLASS__.'_selected_objects');
  129.         
  130.         TTransaction::open('dmdbd');
  131.         $object = new AgetranVagaIdoso($param['key']); // load the object
  132.         if (isset($selected_objects[$object->id]))
  133.         {
  134.             unset($selected_objects[$object->id]);
  135.         }
  136.         else
  137.         {
  138.             $selected_objects[$object->id] = $object->toArray(); // add the object inside the array
  139.         }
  140.         TSession::setValue(__CLASS__.'_selected_objects'$selected_objects); // put the array back to the session
  141.         TTransaction::close();
  142.         
  143.         // reload datagrids
  144.         $this->onReloadfunc_get_arg(0) );
  145.     }
  146.     
  147.     /**
  148.      * Highlight the selected rows
  149.      */
  150.     public function formatRow($value$object$row)
  151.     {
  152.         $selected_objects TSession::getValue(__CLASS__.'_selected_objects');
  153.         
  154.         if ($selected_objects)
  155.         {
  156.             if (in_array( (int) $valuearray_keys$selected_objects ) ) )
  157.             {
  158.                 $row->style "background: #FFD965";
  159.             }
  160.         }
  161.         
  162.         return $value;
  163.     }
  164.     
  165.     /**
  166.      * Show selected records
  167.      */
  168.     public function showResults()
  169.     {
  170.         $datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
  171.         
  172.         $datagrid->addQuickColumn('Número''id''right');
  173.         $datagrid->addQuickColumn('Nome''id_idoso''left');
  174.         $datagrid->addQuickColumn('Emissão''emissao''left');
  175.         $datagrid->addQuickColumn('UF''uf''left');
  176.         $datagrid->addQuickColumn('Cidade''cidade''left');
  177.         $datagrid->addQuickColumn('Orgao Expedidor''orgao_expedidor''left');
  178.         $datagrid->addQuickColumn('Validade''validade''left');
  179.         
  180.         // create the datagrid model
  181.         $datagrid->createModel();
  182.         
  183.         $selected_objects TSession::getValue(__CLASS__.'_selected_objects');
  184.         ksort($selected_objects);
  185.         if ($selected_objects)
  186.         {
  187.             $datagrid->clear();
  188.             foreach ($selected_objects as $selected_object)
  189.             {
  190.                 $datagrid->addItem( (object) $selected_object );
  191.             }
  192.         }
  193.         
  194.         $win TWindow::create('Results'0.60.6);
  195.         $win->add($datagrid);
  196.         $win->show();
  197.     }
  198. }
  199. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


RS

Vou tentar achar algo.
RS

achei o problema mudei de: TPage para TStandardList e funcionou

  1. <?php
  2. class AgetranVagaIdosoSelectionList extends TPage
  3. {
  4. para
  5. class AgetranVagaIdosoSelectionList extends TStandardList
  6. {
  7. ?>