PA
Problema com o onSearch
Bom dia, prezados, estou enfrentando um problema com a função do onSearch a qual não consigo gerar resultados ao procurar, já tentei de diversas formas, porém encontro resistência, vale ressaltar que sou novo no framework.
Abaixo segue o código para que possam visualizar:
Abaixo segue o código para que possam visualizar:
- <?php
- class RondaList extends TStandardList
- {
- protected $form; // registration form
- protected $datagrid; // listing
- protected $pageNavigation;
- // trait with onReload, onSearch, onDelete...
- use Adianti\Base\AdiantiStandardListTrait;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- $this->setDatabase('permission'); // defines the database
- $this->setActiveRecord('Ronda'); // defines the active record
- $this->addFilterField('fk_id_cad_vigia', 'like', 'fk_id_cad_vigia'); // filter field, operator, form field
- $this->setDefaultOrder('id', 'asc'); // define the default order
- // creates the form
- $this->form = new BootstrapFormBuilder('datagrid_ronda');
- $this->form->setFormTitle('Rondas realizadas');
- $descricao = new TEntry('descricao');
- $this->form->addFields( [new TLabel('Ronda')], [$descricao] );
- // add form actions
- $this->form->addAction('Buscar', new TAction([$this, 'onSearch']), 'fa:search white')->class = 'btn btn-sm btn-primary';
- $this->form->addActionLink('Limpar', new TAction([$this, 'clear']), 'fa:eraser white')->class = 'btn btn-sm btn-info';
- // creates the DataGrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->width = "100%";
- // creates the datagrid columns
- $col_cad_vigia = new TDataGridColumn('fk_id_cad_vigia', 'Nome', 'center', '25%');
- $data_ronda = new TDataGridColumn('data_tempo', 'Data', 'center', '50%');
- $status_ronda = new TDataGridColumn('fk_id_dados_unidade', 'Ronda', 'center', '25%');
- $this->datagrid->addColumn($col_cad_vigia);
- $this->datagrid->addColumn($data_ronda);
- $this->datagrid->addColumn($status_ronda);
- //Setar uma máscara ao campo data
- $data_ronda->setTransformer( function($value, $object, $row) {
- $data = TDate::date2br($value );
- return $data;
- });
- $status_ronda->setTransformer( function($value, $object, $row) {
- $class = ($value=='N') ? 'warning' : 'success';
- $label = ($value=='N') ? 'A caminho' : 'Ronda realizada';
- $div = new TElement('span');
- $div->class="label label-{$class}";
- $div->style="text-shadow:none; font-size:12px; font-weight:lighter";
- $div->add($label);
- return $div;
- });
- $col_cad_vigia->setAction( new TAction([$this, 'onReload']), ['order' => 'fk_id_cad_vigia']);
- $data_ronda->setAction( new TAction([$this, 'onReload']), ['order' => 'data_tempo']);
- $status_ronda->setAction( new TAction([$this, 'onReload']), ['order' => 'fk_id_dados_unidade']);
- //botão com ação de editar
- $action1 = new TDataGridAction([$this, 'onEdit']);
- $action1->setLabel('Roteiro');
- $action1->setImage('fa:map-marker blue fa-lg');
- $action1->setFields(['id']);
- $this->datagrid->addAction($action1);
- // create the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- // creates the page structure using a table
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- $vbox->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
- // add the table inside the page
- parent::add($vbox);
- }
- /**
- * Clear filters
- */
- function clear()
- {
- $this->clearFilters();
- $this->onReload();
- }
- function onEdit(){
- }
- function onSearch(){
- $data = $this->form->getData();
- if(isset($data->descricao)){
- if (isset($data->descricao) AND strlen(trim($data->descricao)) > 0) {
- $filter = new TFilter('descricao', 'ilike', "%{$data->descricao}%"); // create the filter
- TSession::setValue('SegCadastroRonda_filter_descricao', $filter); // stores the filter in the session
- }
- //$criterio = new TCriteria;
- //$criterio->add(new TFilter('fk_id_cad_vigia', 'like', '%{$data->fk_id_cad_vigia}%'));
- //TSession::setValue('criterio', $criterio);
- $this->form->setData($data);
- }
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- //echo $data->fk_id_cad_vigia;
- }
- function onReload($param = NULL){
- try {
- TTransaction::open('permission');
- $repositorio = new TRepository('Ronda');
- $objetos = $repositorio->load(new TCriteria);
- $this->datagrid->clear();
- if($objetos){
- foreach ($objetos as $objeto) {
- $vigia = new Vigia($objeto->fk_id_cad_vigia);
- $objeto->data_tempo = $vigia->data_cadastro;
- $objeto->fk_id_cad_vigia = $vigia->nome;
- $this->datagrid->addItem($objeto);
- }
- }
- TTransaction::close();
- } catch (Exception $e) {
- new TMessage('error', $e->getMessage());
- }
- }
- }
Peter,
Revise a linha 113, troque 'ilike' por 'like'
$filter = new TFilter('descricao', 'ilike', "%{$data->descricao}%"); // create the filter
Abs
Olá meu nobre, agradeço muitíssimo pela cooperação e ajuda, porém, ainda persiste em carregar e não retornar uma resposta.
Peter,
Veja essas linhas:
linha 19: $this->setDatabase('permission'); // defines the database
linha 132: TTransaction::open('permission');
'permission', vem como padrão do framework o acesso aos dados das permissões de usuários
Você criou o arquivo ini do database de sua aplicação (da tabela Ronda) ?
Se positivo, você terá que substituir o 'permission' destas 2 linhas pelo nome do arquivo que você criou.
Eu não criei meu arquivo .ini não, eu alterei o permission e utilizo este arquivo.
Minha dúvida ainda persiste, alguém poderia me ajudar?
Agradeço pela tentativa Now Sistemas, muito obrigado.
Faltou aplicar o Filtro no onReload:
Faltou aplicar o Filtro no onReload: