Apresentar no datagrid uma coluna de data.. Boa noite, estou com dúvida em como colocar o campo (próximo contato) de datagrid em formato dd/mm/yyyy. Segue o código do formulário e a imagem da tela. ...
RF
Apresentar no datagrid uma coluna de data..  
Fechado
Boa noite, estou com dúvida em como colocar o campo (próximo contato) de datagrid em formato dd/mm/yyyy.
Segue o código do formulário e a imagem da tela.

 
  1. <?php
  2. /**
  3. * ProspeccaoList Listing
  4. * @author <your name here>
  5. */
  6. class ProspeccaoList extends TPage
  7. {
  8. private $form; // form
  9. private $datagrid; // listing
  10. private $pageNavigation;
  11. private $formgrid;
  12. private $loaded;
  13. private $deleteButton;
  14. /**
  15. * Class constructor
  16. * Creates the page, the form and the listing
  17. */
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. // creates the form
  22. $this->form = new TQuickForm('form_search_Prospeccao');
  23. $this->form->class = 'tform'; // change CSS class
  24. $this->form->style = 'display: table;width:100%'; // change style
  25. //$this->form->setFormTitle('Pesquisa conforme o filtro');
  26. // create the form fields
  27. $customer_cnpj = new TEntry('customer_cnpj');
  28. $rasocial = new TEntry('rasocial');
  29. $acompanhar = new TCombo('acompanhar');
  30. $proximocontato = new TDate('proximocontato');
  31. //Mascara dos campos
  32. $customer_cnpj ->setMask('99.999.999/9999-99');
  33. $proximocontato ->setMask('dd/mm/yyyy');
  34. //Itens do campo acompanhar
  35. $itemGender = array();//opções
  36. $itemGender['Sim'] = 'Sim';
  37. $itemGender['Não'] = 'Não';
  38. // adiciona as opções na lista
  39. $acompanhar->addItems($itemGender);
  40. // add the fields
  41. $this->form->addQuickField('C.N.P.J:', $customer_cnpj, 200 );
  42. $this->form->addQuickField('Razão Social:', $rasocial, 200 );
  43. $this->form->addQuickField('Agendado como Sim ou Não:', $acompanhar, 200 );
  44. $this->form->addQuickField('Data agendada:', $proximocontato, 180 );
  45. // keep the form filled during navigation with session data
  46. $this->form->setData( TSession::getValue('Prospeccao_filter_data') );
  47. // add the search form actions
  48. $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
  49. $this->form->addQuickAction(_t('New'), new TAction(array('ProspeccaoForm', 'onEdit')), 'bs:plus-sign green');
  50. // creates a Datagrid
  51. $this->datagrid = new TDataGrid;
  52. $this->datagrid->style = 'width: 100%';
  53. $this->datagrid->setHeight(300);
  54. // creates the datagrid columns
  55. $column_id = new TDataGridColumn('id', 'N.', 'right');
  56. $column_customer_cnpj = new TDataGridColumn('customer_cnpj', 'CNPJ', 'left');
  57. $column_rasocial = new TDataGridColumn('rasocial', 'R. Social', 'left');
  58. $column_telefone = new TDataGridColumn('telefone', 'Telefone', 'left');
  59. $column_email = new TDataGridColumn('email', 'E-mail', 'left');
  60. $column_acompanhar = new TDataGridColumn('acompanhar', 'Acompanhar', 'left');
  61. $column_proximocontato = new TDataGridColumn('proximocontato', 'Próximo contato', 'left');
  62. // add the columns to the DataGrid
  63. $this->datagrid->addColumn($column_id);
  64. $this->datagrid->addColumn($column_customer_cnpj);
  65. $this->datagrid->addColumn($column_rasocial);
  66. $this->datagrid->addColumn($column_telefone);
  67. $this->datagrid->addColumn($column_email);
  68. $this->datagrid->addColumn($column_acompanhar);
  69. $this->datagrid->addColumn($column_proximocontato);
  70. // create EDIT action
  71. $action_edit = new TDataGridAction(array('ProspeccaoForm', 'onEdit'));
  72. $action_edit->setUseButton(TRUE);
  73. $action_edit->setButtonClass('btn btn-default');
  74. //$action_edit->setLabel(_t('Edit'));
  75. $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  76. $action_edit->setField('id');
  77. $this->datagrid->addAction($action_edit);
  78. // create DELETE action
  79. $action_del = new TDataGridAction(array($this, 'onDelete'));
  80. $action_del->setUseButton(TRUE);
  81. $action_del->setButtonClass('btn btn-default');
  82. //$action_del->setLabel(_t('Delete'));
  83. $action_del->setImage('fa:trash-o red fa-lg');
  84. $action_del->setField('id');
  85. $this->datagrid->addAction($action_del);
  86. // create the datagrid model
  87. $this->datagrid->createModel();
  88. // creates the page navigation
  89. $this->pageNavigation = new TPageNavigation;
  90. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  91. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  92. // Sub menu bonito
  93. $vbox = new TVBox;
  94. $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  95. $vbox->add($this->form);
  96. $vbox->style = 'width: 100%';
  97. $vbox->add($this->datagrid);
  98. $vbox->add($this->pageNavigation);
  99. parent::add($vbox);
  100. }
  101. /**
  102. * Inline record editing
  103. * @param $param Array containing:
  104. * key: object ID value
  105. * field name: object attribute to be updated
  106. * value: new attribute content
  107. */
  108. public function onInlineEdit($param)
  109. {
  110. try
  111. {
  112. // get the parameter $key
  113. $field = $param['field'];
  114. $key = $param['key'];
  115. $value = $param['value'];
  116. TTransaction::open('samples'); // open a transaction with database
  117. $object = new Prospeccao($key); // instantiates the Active Record
  118. $object->{$field} = $value;
  119. $object->store(); // update the object in the database
  120. TTransaction::close(); // close the transaction
  121. $this->onReload($param); // reload the listing
  122. new TMessage('info', "Record Updated");
  123. }
  124. catch (Exception $e) // in case of exception
  125. {
  126. new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
  127. TTransaction::rollback(); // undo all pending operations
  128. }
  129. }
  130. /**
  131. * Register the filter in the session
  132. */
  133. public function onSearch()
  134. {
  135. // get the search form data
  136. $data = $this->form->getData();
  137. // clear session filters
  138. TSession::setValue('ProspeccaoList_filter_customer_cnpj', NULL);
  139. TSession::setValue('ProspeccaoList_filter_rasocial', NULL);
  140. TSession::setValue('ProspeccaoList_filter_acompanhar', NULL);
  141. TSession::setValue('ProspeccaoList_filter_proximocontato', NULL);
  142. if (isset($data->customer_cnpj) AND ($data->customer_cnpj)) {
  143. $filter = new TFilter('customer_cnpj', 'like', "%{$data->customer_cnpj}%"); // create the filter
  144. TSession::setValue('ProspeccaoList_filter_customer_cnpj', $filter); // stores the filter in the session
  145. }
  146. if (isset($data->rasocial) AND ($data->rasocial)) {
  147. $filter = new TFilter('rasocial', 'like', "%{$data->rasocial}%"); // create the filter
  148. TSession::setValue('ProspeccaoList_filter_rasocial', $filter); // stores the filter in the session
  149. }
  150. if (isset($data->acompanhar) AND ($data->acompanhar)) {
  151. $filter = new TFilter('acompanhar', 'like', "%{$data->acompanhar}%"); // create the filter
  152. TSession::setValue('ProspeccaoList_filter_acompanhar', $filter); // stores the filter in the session
  153. }
  154. if (isset($data->proximocontato) AND ($data->proximocontato)) {
  155. $filter = new TFilter('proximocontato', 'like', "%{$data->proximocontato}%"); // create the filter
  156. TSession::setValue('ProspeccaoList_filter_proximocontato', $filter); // stores the filter in the session
  157. }
  158. // fill the form with data again
  159. $this->form->setData($data);
  160. // keep the search data in the session
  161. TSession::setValue('Prospeccao_filter_data', $data);
  162. $param=array();
  163. $param['offset'] =0;
  164. $param['first_page']=1;
  165. $this->onReload($param);
  166. }
  167. /**
  168. * Load the datagrid with data
  169. */
  170. public function onReload($param = NULL)
  171. {
  172. try
  173. {
  174. // open a transaction with database 'samples'
  175. TTransaction::open('samples');
  176. // creates a repository for Prospeccao
  177. $repository = new TRepository('Prospeccao');
  178. $limit = 10;
  179. // creates a criteria
  180. $criteria = new TCriteria;
  181. // default order
  182. if (empty($param['order']))
  183. {
  184. $param['order'] = 'id';
  185. $param['direction'] = 'asc';
  186. }
  187. $criteria->setProperties($param); // order, offset
  188. $criteria->setProperty('limit', $limit);
  189. if (TSession::getValue('ProspeccaoList_filter_customer_cnpj')) {
  190. $criteria->add(TSession::getValue('ProspeccaoList_filter_customer_cnpj')); // add the session filter
  191. }
  192. if (TSession::getValue('ProspeccaoList_filter_rasocial')) {
  193. $criteria->add(TSession::getValue('ProspeccaoList_filter_rasocial')); // add the session filter
  194. }
  195. if (TSession::getValue('ProspeccaoList_filter_acompanhar')) {
  196. $criteria->add(TSession::getValue('ProspeccaoList_filter_acompanhar')); // add the session filter
  197. }
  198. if (TSession::getValue('ProspeccaoList_filter_proximocontato')) {
  199. $criteria->add(TSession::getValue('ProspeccaoList_filter_proximocontato')); // add the session filter
  200. }
  201. // load the objects according to criteria
  202. $objects = $repository->load($criteria, FALSE);
  203. if (is_callable($this->transformCallback))
  204. {
  205. call_user_func($this->transformCallback, $objects, $param);
  206. }
  207. $this->datagrid->clear();
  208. if ($objects)
  209. {
  210. // iterate the collection of active records
  211. foreach ($objects as $object)
  212. {
  213. // add the object inside the datagrid
  214. $this->datagrid->addItem($object);
  215. }
  216. }
  217. // reset the criteria for record count
  218. $criteria->resetProperties();
  219. $count= $repository->count($criteria);
  220. $this->pageNavigation->setCount($count); // count of records
  221. $this->pageNavigation->setProperties($param); // order, page
  222. $this->pageNavigation->setLimit($limit); // limit
  223. // close the transaction
  224. TTransaction::close();
  225. $this->loaded = true;
  226. }
  227. catch (Exception $e) // in case of exception
  228. {
  229. // shows the exception error message
  230. new TMessage('error', $e->getMessage());
  231. // undo all pending operations
  232. TTransaction::rollback();
  233. }
  234. }
  235. /**
  236. * Ask before deletion
  237. */
  238. public function onDelete($param)
  239. {
  240. // define the delete action
  241. $action = new TAction(array($this, 'Delete'));
  242. $action->setParameters($param); // pass the key parameter ahead
  243. // shows a dialog to the user
  244. new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  245. }
  246. /**
  247. * Delete a record
  248. */
  249. public function Delete($param)
  250. {
  251. try
  252. {
  253. $key=$param['key']; // get the parameter $key
  254. TTransaction::open('samples'); // open a transaction with database
  255. $object = new Prospeccao($key, FALSE); // instantiates the Active Record
  256. $object->delete(); // deletes the object from the database
  257. TTransaction::close(); // close the transaction
  258. $this->onReload( $param ); // reload the listing
  259. new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
  260. }
  261. catch (Exception $e) // in case of exception
  262. {
  263. new TMessage('error', $e->getMessage()); // shows the exception error message
  264. TTransaction::rollback(); // undo all pending operations
  265. }
  266. }
  267. /**
  268. * method show()
  269. * Shows the page
  270. */
  271. public function show()
  272. {
  273. // check if the datagrid is already loaded
  274. if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
  275. {
  276. if (func_num_args() > 0)
  277. {
  278. $this->onReload( func_get_arg(0) );
  279. }
  280. else
  281. {
  282. $this->onReload();
  283. }
  284. }
  285. parent::show();
  286. }
  287. }

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


MC

Simples, fácil e rápido.. kkkkk


no onReload

 
  1. <?php
  2. if ($objects)
  3. {
  4. // iterate the collection of active records
  5. foreach ($objects as $object)
  6. {
  7. $object->proximocontato = TDate::date2br($object->proximocontato);
  8. $this->datagrid->addItem($object);
  9. }
  10. }
  11. ?>




Abraços
RF

Funcionou perfeitamente, muito obrigado, testado e ajustado.
PD

Uma maneira mais simples, sem precisar reescrever o onReload():
www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra