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

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