Já Carregar o DataGrid com o filtro Pessoal, estou precisando da ajuda de vocês. Tenho um formulário que é usado para consulta de dados e andamento de um protocolo. Então uso ele chamando o método onEdit passando os dados do código. Mas o DataGrid não entra filtrando pelo codigo. Já até tentei pelo onReload mas carrega todos os dados da tabela. Pelo código abaixo do construtor, não vem nada. Pelo onLoad vem to...
SJ
Já Carregar o DataGrid com o filtro  
Pessoal, estou precisando da ajuda de vocês.

Tenho um formulário que é usado para consulta de dados e andamento de um protocolo.
Então uso ele chamando o método onEdit passando os dados do código.

Mas o DataGrid não entra filtrando pelo codigo.
Já até tentei pelo onReload mas carrega todos os dados da tabela.

Pelo código abaixo do construtor, não vem nada.
Pelo onLoad vem todos os dados da tabela, não respeitando o filtro

Alguém pode dar um help?


 
  1. <?php
  2. use Adianti\Control\TPage;
  3. use Adianti\Control\TAction;
  4. use Adianti\Widget\Dialog\TMessage;
  5. use Adianti\Wrapper\BootstrapFormBuilder;
  6. class ProcessoAnonimoFormTeste extends TPage
  7. {
  8. private $form;
  9. // trait with saveFile, saveFiles, ...
  10. use Adianti\Base\AdiantiFileSaveTrait;
  11. // trait with onReload, onSearch, onDelete...
  12. use Adianti\Base\AdiantiStandardListTrait;
  13. public function __construct($param)
  14. {
  15. parent::__construct();
  16. // $this->setDatabase('bdados'); // defines the database
  17. // $this->setActiveRecord('ProcessoTramitacao'); // defines the active record
  18. // $this->addFilterField('codigo', '=', 'codigo'); // filter field, operator, form field
  19. // $this->setDefaultOrder('id', 'desc'); // define the default order
  20. // $criteria = new TCriteria();
  21. // $criteria->add(new TFilter('codigo','=',TSession::getValue('codigo')));
  22. // $this->setCriteria($criteria);
  23. //------------------------------------------------------------------------------------------
  24. // Formulário
  25. //------------------------------------------------------------------------------------------
  26. $this->form = new BootstrapFormBuilder('meu_form');
  27. $this->form->setFormTitle('<b>Manifestação</b>');
  28. $this->form->setClientValidation( true ); // Habilita as validações nativas do HTML no Cliente(tips)
  29. $this->form->setFieldSizes('100%'); //IMPORTANTE!!! Puxa todos os campos do formulário para 100%
  30. //------------------------------------------------------------------------------------------
  31. // Cria os Elementos
  32. //------------------------------------------------------------------------------------------
  33. $id = new THidden('id');
  34. $codigo = new THidden('codigo');
  35. $dt_cadastro = new TDate('dt_cadastro');
  36. $hr_cadastro = new TTime('hr_cadastro');
  37. $contato_id = new THidden('contato_id');
  38. $ocor_endereco = new TEntry('ocor_endereco');
  39. $ocor_bairro = new TEntry('ocor_bairro');
  40. $ocor_referencia = new TEntry('ocor_referencia');
  41. $ocor_descricao = new TText('ocor_descricao');
  42. $faixa_idade_id = new TDBCombo('faixa_idade_id', 'bdados', 'FaixaIdade' , 'id', 'descricao');
  43. $solicitacao_id = new TDBCombo('solicitacao_id', 'bdados', 'Solicitacao' , 'id', 'descricao');
  44. $assunto_id = new TDBCombo('assunto_id', 'bdados', 'Assunto' , 'id', 'descricao');
  45. //------------------------------------------------------------------------------------------
  46. // Configurações dos campos
  47. //------------------------------------------------------------------------------------------
  48. $contato_id->setValue(1);
  49. $dt_cadastro->setDatabaseMask('yyyy-mm-dd');
  50. $ocor_endereco->forceUpperCase();
  51. $ocor_bairro->forceUpperCase();
  52. $ocor_referencia->forceUpperCase();
  53. $assunto_id->enableSearch();
  54. $id->setEditable(FALSE);
  55. $dt_cadastro->setEditable(FALSE);
  56. $hr_cadastro->setEditable(FALSE);
  57. //------------------------------------------------------------------------------------------
  58. // Adiciona os campos no form
  59. //------------------------------------------------------------------------------------------
  60. $this->form->appendPage('Dados da Manifestação');
  61. $this->form->addFields( [ $id ] )->style = 'display:none';
  62. $this->form->addFields( [ $codigo ] )->style = 'display:none';
  63. $this->form->addFields( [ $dt_cadastro ] )->style = 'display:none';
  64. $this->form->addFields( [ $hr_cadastro ] )->style = 'display:none';
  65. $this->form->addFields( [ $contato_id ] )->style = 'display:none';
  66. $row = $this->form->addFields( [ new TLabel('Tipo de Solicitação') , $solicitacao_id ],
  67. [ new TLabel('Assunto') , $assunto_id ],
  68. [ new TLabel('Faixa de Idade') , $faixa_idade_id ]);
  69. $row->layout = [ 'col-sm-3', 'col-sm-7', 'col-sm-2'];
  70. // Divisão---------------------------------------------------------------------------------
  71. $label = new TLabel('Dados da Manifestação', '#6979BF', 12, 'bi');
  72. $label->style = 'text-align:left;border-bottom: 1px solid gray; width: 100%; padding-top: 20px' ;
  73. $this->form->addContent( [$label] );
  74. // Linha-----------------------------------------------------------------------------------
  75. $row = $this->form->addFields( [ new TLabel('Endereço') ,$ocor_endereco ],
  76. [ new TLabel('Bairro') ,$ocor_bairro ]);
  77. $row->layout = [ 'col-sm-8', 'col-sm-4'];
  78. // Linha-----------------------------------------------------------------------------------
  79. $row = $this->form->addFields( [ new TLabel('Referência') ,$ocor_referencia ]);
  80. $row->layout = [ 'col-sm-12' ];
  81. // Linha-----------------------------------------------------------------------------------
  82. $row = $this->form->addFields( [ new TLabel('Descrição') ,$ocor_descricao ]);
  83. $row->layout = [ 'col-sm-12' ];
  84. // Anexos-----------------------------------------------------------------------------------
  85. $this->form->appendPage('Anexos');
  86. $camera1 = new TImageCapture('camera1');
  87. $camera2 = new TImageCapture('camera2');
  88. $camera3 = new TImageCapture('camera3');
  89. $camera4 = new TImageCapture('camera4');
  90. $arquivos = new TMultiFile('arquivos');
  91. $camera1->setSize(250, 250);
  92. $camera1->setCropSize(250, 250);
  93. $camera1->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
  94. $camera1->enableFileHandling();
  95. $camera2->setSize(250, 250);
  96. $camera2->setCropSize(250, 250);
  97. $camera2->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
  98. $camera2->enableFileHandling();
  99. $camera3->setSize(250, 250);
  100. $camera3->setCropSize(250, 250);
  101. $camera3->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
  102. $camera3->enableFileHandling();
  103. $camera4->setSize(250, 250);
  104. $camera4->setCropSize(250, 250);
  105. $camera4->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg'] );
  106. $camera4->enableFileHandling();
  107. $arquivos->setAllowedExtensions( ['gif', 'png', 'jpg', 'jpeg','pdf'] );
  108. $arquivos->enableFileHandling();
  109. //$arquivos->enableImageGallery();
  110. $arquivos->enablePopover('Preview', '<img style="max-width:300px" src="download.php?file={file_name}">');
  111. // Divisão---------------------------------------------------------------------------------
  112. $label = new TLabel('Imagens da Câmera', '#6979BF', 12, 'bi');
  113. $label->style = 'text-align:left;border-bottom: 1px solid gray; width: 100%; padding-top: 20px' ;
  114. $this->form->addContent( [$label] );
  115. $row = $this->form->addFields( [ $camera1 ],
  116. [ $camera2 ],
  117. [ $camera3 ],
  118. [ $camera4 ]);
  119. $row->layout = [ 'col-sm-3', 'col-sm-3', 'col-sm-3', 'col-sm-3'];
  120. // Divisão---------------------------------------------------------------------------------
  121. $label = new TLabel('Imagens da Galeria', '#6979BF', 12, 'bi');
  122. $label->style = 'text-align:left;border-bottom: 1px solid gray; width: 100%; padding-top: 20px' ;
  123. $this->form->addContent( [$label] );
  124. $this->form->addFields( [new TLabel('Images')], [$arquivos] );
  125. // DESABILITA OS CAMPOS SE FOR EDIÇÃO-------------------------------------------------------
  126. if (isset($param['key']) )
  127. {
  128. $solicitacao_id->setEditable(FALSE);
  129. $ocor_endereco->setEditable(FALSE);
  130. $ocor_bairro->setEditable(FALSE);
  131. $ocor_referencia->setEditable(FALSE);
  132. $ocor_descricao->setEditable(FALSE);
  133. $faixa_idade_id->setEditable(FALSE);
  134. $solicitacao_id->setEditable(FALSE);
  135. $assunto_id->setEditable(FALSE);
  136. $arquivos->setEditable(FALSE);
  137. $camera1->setEditable(FALSE);
  138. $camera2->setEditable(FALSE);
  139. $camera3->setEditable(FALSE);
  140. $camera4->setEditable(FALSE);
  141. //$camera4->disableField('meu_form', $camera4->remove);
  142. //TField::disableField('meu_form', $camera4->remove);
  143. }
  144. // Validações------------------------------------------------------------------------------
  145. $solicitacao_id->addValidation('Tipo de Solicitação' , new TRequiredValidator);
  146. $assunto_id->addValidation('Assunto' , new TRequiredValidator);
  147. $faixa_idade_id->addValidation('Faixa de Idade' , new TRequiredValidator);
  148. $ocor_endereco->addValidation('Endereço' , new TRequiredValidator);
  149. $ocor_bairro->addValidation('Bairro' , new TRequiredValidator);
  150. $ocor_referencia->addValidation('Referência' , new TRequiredValidator);
  151. $ocor_endereco->addValidation('Endereço' , new TMaxLengthValidator, [70]);
  152. $ocor_bairro->addValidation('Bairro' , new TMaxLengthValidator, [40]);
  153. $ocor_referencia->addValidation('Referência' , new TMaxLengthValidator, [130]);
  154. // Adiciona os Botões de Ação - addAction(Na barra de Baixo) - addHeaderAction(Na barra de cima)
  155. $this->form->addAction( 'Salvar', new TAction( [$this, 'onSave'] ), 'fa:save green' );
  156. $this->form->addActionLink( 'Limpar', new TAction( [$this, 'onClear'] ), 'fa:eraser red' ); // Executa a ação sem POST
  157. $this->form->addExpandButton();
  158. // creates the DataGrid
  159. $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  160. $this->datagrid->width = "100%";
  161. // creates the datagrid columns
  162. $col_data = new TDataGridColumn('dt_tramita' , 'Dt. Movim.' , 'center', '10%');
  163. $col_hora = new TDataGridColumn('hr_tramita' , 'Hr. Movim.' , 'cente' , '10%');
  164. $col_movimento = new TDataGridColumn('movimento_id', 'Tipo' , 'left' , '20%');
  165. $col_destino = new TDataGridColumn('destino_id' , 'Local' , 'left' , '20%');
  166. $col_destinatario = new TDataGridColumn('destinatario', 'Responsável', 'left' , '20%');
  167. $col_despaco = new TDataGridColumn('despacho' , 'Despacho' , 'left' , '20%');
  168. $col_data->setTransformer( array($this,'formatDate'));
  169. //$col_state = new TDataGridColumn('state->name', 'State', 'center', '30%');
  170. $this->datagrid->addColumn($col_data);
  171. $this->datagrid->addColumn($col_hora);
  172. $this->datagrid->addColumn($col_movimento);
  173. $this->datagrid->addColumn($col_destino);
  174. $this->datagrid->addColumn($col_destinatario);
  175. $this->datagrid->addColumn($col_despaco);
  176. // create the datagrid model
  177. $this->datagrid->createModel();
  178. // creates the page navigation
  179. $this->pageNavigation = new TPageNavigation;
  180. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  181. // creates the page structure using a table
  182. $vbox = new TVBox;
  183. $vbox->style = 'width: 100%';
  184. $vbox->add($this->form);
  185. $vbox->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
  186. // // Adiciona o formulário na tela
  187. // parent::add($this->form);
  188. // add the table inside the page
  189. parent::add($vbox);
  190. }
  191. //======================================================================================================================
  192. // EDITAR OS DADOS
  193. //======================================================================================================================
  194. public function onEdit($param)
  195. {
  196. try
  197. {
  198. if (isset($param['key']))
  199. {
  200. TTransaction::open('bdados');
  201. $key = $param['key']; // Pega a chave do registro
  202. $Processo = new Processo( $key ); // Carrega os dados
  203. $Processo->arquivos = ProcessoArquivos::where('processo_id', '=', $param['key'])->getIndexedArray('id', 'arquivo');
  204. $this->form->setData($Processo); // Seta os dados na tela
  205. TTransaction::close();
  206. return $Processo;
  207. }
  208. else
  209. {
  210. $this->form->clear(true);
  211. }
  212. }
  213. catch (exception $e)
  214. {
  215. new TMessage('error', $e->getMessage());
  216. TTransaction::rollback();
  217. }
  218. }
  219. //======================================================================================================================
  220. // TRANSFORMA A DATA NO PADRÃO BRASILEIRO
  221. //======================================================================================================================
  222. public function formatDate($date, $object)
  223. {
  224. if ($date != NULL){
  225. $dt = new DateTime($date);
  226. return $dt->format('d/m/Y');
  227. }else{
  228. return NULL;
  229. }
  230. }
  231. //======================================================================================================================
  232. function onReload($param = NULL)
  233. {
  234. try
  235. {
  236. // open a transaction with database 'samples'
  237. TTransaction::open('bdados');
  238. // creates a repository for City
  239. $repository = new TRepository('ProcessoTramitacao');
  240. $limit = 10;
  241. // creates a criteria
  242. $criteria = new TCriteria;
  243. $criteria->setProperties($param); // order, offset
  244. $criteria->setProperty('limit', $limit);
  245. if (TSession::getValue('codigo'))
  246. {
  247. // add the filter stored in the session to the criteria
  248. $criteria->add(TSession::getValue('codigo'));
  249. }
  250. // load the objects according to criteria
  251. $objects = $repository->load($criteria);
  252. $this->datagrid->clear();
  253. if ($objects)
  254. {
  255. // iterate the collection of active records
  256. foreach ($objects as $object)
  257. {
  258. // add the object inside the datagrid
  259. $this->datagrid->addItem($object);
  260. }
  261. }
  262. // reset the criteria for record count
  263. $criteria->resetProperties();
  264. $count = $repository->count($criteria);
  265. $this->pageNavigation->setCount($count); // count of records
  266. $this->pageNavigation->setProperties($param); // order, page
  267. $this->pageNavigation->setLimit($limit); // limit
  268. // close the transaction
  269. TTransaction::close();
  270. $this->loaded = true;
  271. }
  272. catch (Exception $e) // in case of exception
  273. {
  274. new TMessage('error', $e->getMessage()); // shows the exception error message
  275. TTransaction::rollback(); // undo all pending operations
  276. }
  277. }
  278. function show()
  279. {
  280. // check if the datagrid is already loaded
  281. if (!$this->loaded)
  282. {
  283. $this->onReload( func_get_arg(0) );
  284. var_dump($this->loaded);
  285. }
  286. parent::show();
  287. }
  288. }
  289. ?>
Editado 21/11/2023 (há 1 ano) - Clique para ver alterações

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (1)


PD

O erro está nessa linha:
 
  1. <?php
  2. $criteria->add(TSession::getValue('codigo'));
  3. ?>


O $criteria->add() deve receber um objeto da classe TFilter, e não um código ;-)
 
  1. <?php
  2. $criteria->add( new TFilter( ...) );
  3. ?>