DataGrid com valor numerico Bom dia... Estou com dificuldade em apresentar os campos Maior valor e Menor valor na grid do formulário, como fazer isso? Segue anexo o código do formulário e desenho da tela. ...
RF
DataGrid com valor numerico  
Bom dia...

Estou com dificuldade em apresentar os campos Maior valor e Menor valor na grid do formulário, como fazer isso? Segue anexo o código do formulário e desenho da tela.

 
  1. <?php
  2. /**
  3. * ListaCadatroProdutos Form List
  4. * @author <your name here>
  5. */
  6. class ListaCadatroProdutos extends TPage
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. protected $loaded;
  12. /**
  13. * Form constructor
  14. * @param $param Request
  15. */
  16. public function __construct( $param )
  17. {
  18. parent::__construct();
  19. // creates the form
  20. $this->form = new TQuickForm('form_Produto');
  21. $this->form->class = 'tform'; // change CSS class
  22. $this->form->style = 'display: table;width:100%'; // change style
  23. $this->form->setFormTitle('Produto');
  24. // create the form fields
  25. $id = new TEntry('id');
  26. $tipo = new TCombo('tipo');
  27. $bairro = new TEntry('bairro');
  28. $unidis = new TEntry('unidis');
  29. $vlmaior = new TEntry('vlmaior');
  30. $vlmenor = new TEntry('vlmenor');
  31. $empreendimento = new TEntry('empreendimento');
  32. // definição dos formatos dos campos
  33. $vlmaior -> setNumericMask(2,',', '.', true);
  34. $vlmenor -> setNumericMask(2,',', '.', true);
  35. $empreendimento ->style = "text-transform: uppercase";
  36. $bairro ->style = "text-transform: uppercase";
  37. $unidis ->style = "text-transform: uppercase";
  38. $id ->setEditable(FALSE);
  39. //Itens do estagio
  40. $itemEstagio= array();
  41. $itemEstagio['NA PLANTA'] = 'NA PLANTA';
  42. $itemEstagio['PRONTO PARA MORAR'] = 'PRONTO PARA MORAR';
  43. $tipo->setValue('PRONTO PARA MORAR');
  44. $tipo->addItems($itemEstagio);
  45. // add the fields
  46. $this->form->addQuickField('Código', $id, 200 );
  47. $this->form->addQuickField('Tipo', $tipo, 200 );
  48. $this->form->addQuickField('Bairro', $bairro, 200 );
  49. $this->form->addQuickField('Unidade disponível', $unidis, 450 );
  50. $this->form->addQuickField('Maior valor', $vlmaior, 200 );
  51. $this->form->addQuickField('Menor valor', $vlmenor, 200 );
  52. $this->form->addQuickField('Produto', $empreendimento, 200 );
  53. /** samples
  54. $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  55. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  56. $fieldX->setSize( 100, 40 ); // set size
  57. **/
  58. // create the form actions
  59. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  60. $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
  61. // creates a Datagrid
  62. $this->datagrid = new TDataGrid;
  63. ##LIST_DECORATOR##
  64. $this->datagrid->style = 'width: 100%';
  65. $this->datagrid->setHeight(320);
  66. // $this->datagrid->datatable = 'true';
  67. // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  68. // creates the datagrid columns
  69. $column_id = new TDataGridColumn('id', 'Código', 'left');
  70. $column_tipo = new TDataGridColumn('tipo', 'Tipo', 'left');
  71. $column_bairro = new TDataGridColumn('bairro', 'Bairro', 'left');
  72. $column_unidis = new TDataGridColumn('unidis', 'Unidade disponível', 'left');
  73. $column_vlmaior = new TDataGridColumn('vlmaior', 'Maior valor', 'left');
  74. $column_vlmenor = new TDataGridColumn('vlmenor', 'Menor valor', 'left');
  75. $column_empreendimento = new TDataGridColumn('empreendimento', 'Produto', 'left');
  76. // add the columns to the DataGrid
  77. $this->datagrid->addColumn($column_id);
  78. $this->datagrid->addColumn($column_tipo);
  79. $this->datagrid->addColumn($column_bairro);
  80. $this->datagrid->addColumn($column_unidis);
  81. $this->datagrid->addColumn($column_vlmaior);
  82. $this->datagrid->addColumn($column_vlmenor);
  83. $this->datagrid->addColumn($column_empreendimento);
  84. // creates two datagrid actions
  85. $action1 = new TDataGridAction(array($this, 'onEdit'));
  86. $action1->setUseButton(TRUE);
  87. $action1->setButtonClass('btn btn-default');
  88. //$action1->setLabel(_t('Edit'));
  89. $action1->setImage('fa:pencil-square-o blue fa-lg');
  90. $action1->setField('id');
  91. /*
  92. $action2 = new TDataGridAction(array($this, 'onDelete'));
  93. $action2->setUseButton(TRUE);
  94. $action2->setButtonClass('btn btn-default');
  95. $action2->setLabel(_t('Delete'));
  96. $action2->setImage('fa:trash-o red fa-lg');
  97. $action2->setField('id');
  98. */
  99. // add the actions to the datagrid
  100. $this->datagrid->addAction($action1);
  101. // $this->datagrid->addAction($action2);
  102. // create the datagrid model
  103. $this->datagrid->createModel();
  104. // creates the page navigation
  105. $this->pageNavigation = new TPageNavigation;
  106. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  107. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  108. /* vertical box container
  109. $container = new TVBox;
  110. $container->style = 'width: 90%';
  111. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  112. $container->add($this->form);
  113. $container->add($this->datagrid);
  114. $container->add($this->pageNavigation);
  115. parent::add($container);
  116. */
  117. // Sub Menu Bonito
  118. $container = new TVBox;
  119. $container->style = 'width: 90%';
  120. $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  121. $container->add($this->form);
  122. $container->add(TPanelGroup::pack('', $this->datagrid));
  123. $container->add($this->pageNavigation);
  124. parent::add($container);
  125. }
  126. /**
  127. * Load the datagrid with data
  128. */
  129. public function onReload($param = NULL)
  130. {
  131. try
  132. {
  133. // open a transaction with database 'sample'
  134. TTransaction::open('sample');
  135. // creates a repository for Produto
  136. $repository = new TRepository('Produto');
  137. $limit = 10;
  138. // creates a criteria
  139. $criteria = new TCriteria;
  140. // default order
  141. if (empty($param['order']))
  142. {
  143. $param['order'] = 'id';
  144. $param['direction'] = 'asc';
  145. }
  146. $criteria->setProperties($param); // order, offset
  147. $criteria->setProperty('limit', $limit);
  148. if (TSession::getValue('Produto_filter'))
  149. {
  150. // add the filter stored in the session to the criteria
  151. $criteria->add(TSession::getValue('Produto_filter'));
  152. }
  153. // load the objects according to criteria
  154. $objects = $repository->load($criteria, FALSE);
  155. $this->datagrid->clear();
  156. if ($objects)
  157. {
  158. // iterate the collection of active records
  159. foreach ($objects as $object)
  160. {
  161. // add the object inside the datagrid
  162. $this->datagrid->addItem($object);
  163. }
  164. }
  165. // reset the criteria for record count
  166. $criteria->resetProperties();
  167. $count= $repository->count($criteria);
  168. $this->pageNavigation->setCount($count); // count of records
  169. $this->pageNavigation->setProperties($param); // order, page
  170. $this->pageNavigation->setLimit($limit); // limit
  171. // close the transaction
  172. TTransaction::close();
  173. $this->loaded = true;
  174. }
  175. catch (Exception $e) // in case of exception
  176. {
  177. // shows the exception error message
  178. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  179. // undo all pending operations
  180. TTransaction::rollback();
  181. }
  182. }
  183. /**
  184. * Ask before deletion
  185. */
  186. public function onDelete($param)
  187. {
  188. // define the delete action
  189. $action = new TAction(array($this, 'Delete'));
  190. $action->setParameters($param); // pass the key parameter ahead
  191. // shows a dialog to the user
  192. new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  193. }
  194. /**
  195. * Delete a record
  196. */
  197. public function Delete($param)
  198. {
  199. try
  200. {
  201. $key=$param['key']; // get the parameter $key
  202. TTransaction::open('sample'); // open a transaction with database
  203. $object = new Produto($key, FALSE); // instantiates the Active Record
  204. $object->delete(); // deletes the object from the database
  205. TTransaction::close(); // close the transaction
  206. $this->onReload( $param ); // reload the listing
  207. new TMessage('info', TAdiantiCoreTranslator::translate('Record deleted')); // success message
  208. }
  209. catch (Exception $e) // in case of exception
  210. {
  211. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  212. TTransaction::rollback(); // undo all pending operations
  213. }
  214. }
  215. /**
  216. * Save form data
  217. * @param $param Request
  218. */
  219. public function onSave( $param )
  220. {
  221. try
  222. {
  223. TTransaction::open('sample'); // open a transaction
  224. /**
  225. // Enable Debug logger for SQL operations inside the transaction
  226. TTransaction::setLogger(new TLoggerSTD); // standard output
  227. TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  228. **/
  229. $this->form->validate(); // validate form data
  230. $object = new Produto; // create an empty object
  231. $data = $this->form->getData(); // get form data as array
  232. $data ->bairro = strtoupper($data->bairro);
  233. $data ->empreendimento = strtoupper($data->empreendimento);
  234. $data ->unidis = strtoupper($data->unidis);
  235. $object->fromArray( (array) $data); // load the object with data
  236. $object->store(); // save the object
  237. // get the generated id
  238. $data->id = $object->id;
  239. $this->form->setData($data); // fill form data
  240. TTransaction::close(); // close the transaction
  241. new TMessage('info', TAdiantiCoreTranslator::translate('Record saved')); // success message
  242. $this->onReload(); // reload the listing
  243. }
  244. catch (Exception $e) // in case of exception
  245. {
  246. new TMessage('error', $e->getMessage()); // shows the exception error message
  247. $this->form->setData( $this->form->getData() ); // keep form data
  248. TTransaction::rollback(); // undo all pending operations
  249. }
  250. }
  251. /**
  252. * Clear form data
  253. * @param $param Request
  254. */
  255. public function onClear( $param )
  256. {
  257. $this->form->clear(TRUE);
  258. }
  259. /**
  260. * Load object to form data
  261. * @param $param Request
  262. */
  263. public function onEdit( $param )
  264. {
  265. try
  266. {
  267. if (isset($param['key']))
  268. {
  269. $key = $param['key']; // get the parameter $key
  270. TTransaction::open('sample'); // open a transaction
  271. $object = new Produto($key); // instantiates the Active Record
  272. $this->form->setData($object); // fill the form
  273. TTransaction::close(); // close the transaction
  274. }
  275. else
  276. {
  277. $this->form->clear(TRUE);
  278. }
  279. }
  280. catch (Exception $e) // in case of exception
  281. {
  282. new TMessage('error', $e->getMessage()); // shows the exception error message
  283. TTransaction::rollback(); // undo all pending operations
  284. }
  285. }
  286. /**
  287. * method show()
  288. * Shows the page
  289. */
  290. public function show()
  291. {
  292. // check if the datagrid is already loaded
  293. if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  294. {
  295. $this->onReload( func_get_arg(0) );
  296. }
  297. parent::show();
  298. }
  299. }

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 (5)


PF

Olá colega.
Dê uma olhada em www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra
Neste link aí tem um exemplo...

Também, procurando no forum por setTransformer tem mais exemplos.

T+
PF

Em Tempo, :www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra
PF

a classe é DatagridTransformView
RF

Boa tarde...

Obrigado pela ajuda, mas nenhum dos links indicados funciona. Vou pesquisar em respostas anteriores, talvez alguem já tenha a resposta certa.
PF

Procure no tutor, em Datagrid, Datagrid transformers... Copiei e colei o endereço, mas não sei porque cargas dagua, o link não vai completo... Espero ter ajudado. T+