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.
Segue o código do formulário e a imagem da tela.
- <?php
- /**
- * ProspeccaoList Listing
- * @author <your name here>
- */
- class ProspeccaoList extends TPage
- {
- private $form; // form
- private $datagrid; // listing
- private $pageNavigation;
- private $formgrid;
- private $loaded;
- private $deleteButton;
- /**
- * Class constructor
- * Creates the page, the form and the listing
- */
- public function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new TQuickForm('form_search_Prospeccao');
- $this->form->class = 'tform'; // change CSS class
- $this->form->style = 'display: table;width:100%'; // change style
- //$this->form->setFormTitle('Pesquisa conforme o filtro');
- // create the form fields
- $customer_cnpj = new TEntry('customer_cnpj');
- $rasocial = new TEntry('rasocial');
- $acompanhar = new TCombo('acompanhar');
- $proximocontato = new TDate('proximocontato');
- //Mascara dos campos
- $customer_cnpj ->setMask('99.999.999/9999-99');
- $proximocontato ->setMask('dd/mm/yyyy');
- //Itens do campo acompanhar
- $itemGender = array();//opções
- $itemGender['Sim'] = 'Sim';
- $itemGender['Não'] = 'Não';
- // adiciona as opções na lista
- $acompanhar->addItems($itemGender);
- // add the fields
- $this->form->addQuickField('C.N.P.J:', $customer_cnpj, 200 );
- $this->form->addQuickField('Razão Social:', $rasocial, 200 );
- $this->form->addQuickField('Agendado como Sim ou Não:', $acompanhar, 200 );
- $this->form->addQuickField('Data agendada:', $proximocontato, 180 );
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('Prospeccao_filter_data') );
- // add the search form actions
- $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
- $this->form->addQuickAction(_t('New'), new TAction(array('ProspeccaoForm', 'onEdit')), 'bs:plus-sign green');
- // creates a Datagrid
- $this->datagrid = new TDataGrid;
- $this->datagrid->style = 'width: 100%';
- $this->datagrid->setHeight(300);
- // creates the datagrid columns
- $column_id = new TDataGridColumn('id', 'N.', 'right');
- $column_customer_cnpj = new TDataGridColumn('customer_cnpj', 'CNPJ', 'left');
- $column_rasocial = new TDataGridColumn('rasocial', 'R. Social', 'left');
- $column_telefone = new TDataGridColumn('telefone', 'Telefone', 'left');
- $column_email = new TDataGridColumn('email', 'E-mail', 'left');
- $column_acompanhar = new TDataGridColumn('acompanhar', 'Acompanhar', 'left');
- $column_proximocontato = new TDataGridColumn('proximocontato', 'Próximo contato', 'left');
- // add the columns to the DataGrid
- $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_customer_cnpj);
- $this->datagrid->addColumn($column_rasocial);
- $this->datagrid->addColumn($column_telefone);
- $this->datagrid->addColumn($column_email);
- $this->datagrid->addColumn($column_acompanhar);
- $this->datagrid->addColumn($column_proximocontato);
- // create EDIT action
- $action_edit = new TDataGridAction(array('ProspeccaoForm', 'onEdit'));
- $action_edit->setUseButton(TRUE);
- $action_edit->setButtonClass('btn btn-default');
- //$action_edit->setLabel(_t('Edit'));
- $action_edit->setImage('fa:pencil-square-o blue fa-lg');
- $action_edit->setField('id');
- $this->datagrid->addAction($action_edit);
- // create DELETE action
- $action_del = new TDataGridAction(array($this, 'onDelete'));
- $action_del->setUseButton(TRUE);
- $action_del->setButtonClass('btn btn-default');
- //$action_del->setLabel(_t('Delete'));
- $action_del->setImage('fa:trash-o red fa-lg');
- $action_del->setField('id');
- $this->datagrid->addAction($action_del);
- // 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());
- // Sub menu bonito
- $vbox = new TVBox;
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- $vbox->style = 'width: 100%';
- $vbox->add($this->datagrid);
- $vbox->add($this->pageNavigation);
- parent::add($vbox);
- }
- /**
- * Inline record editing
- * @param $param Array containing:
- * key: object ID value
- * field name: object attribute to be updated
- * value: new attribute content
- */
- public function onInlineEdit($param)
- {
- try
- {
- // get the parameter $key
- $field = $param['field'];
- $key = $param['key'];
- $value = $param['value'];
- TTransaction::open('samples'); // open a transaction with database
- $object = new Prospeccao($key); // instantiates the Active Record
- $object->{$field} = $value;
- $object->store(); // update the object in the database
- TTransaction::close(); // close the transaction
- $this->onReload($param); // reload the listing
- new TMessage('info', "Record Updated");
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', '<b>Error</b> ' . $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- // clear session filters
- TSession::setValue('ProspeccaoList_filter_customer_cnpj', NULL);
- TSession::setValue('ProspeccaoList_filter_rasocial', NULL);
- TSession::setValue('ProspeccaoList_filter_acompanhar', NULL);
- TSession::setValue('ProspeccaoList_filter_proximocontato', NULL);
- if (isset($data->customer_cnpj) AND ($data->customer_cnpj)) {
- $filter = new TFilter('customer_cnpj', 'like', "%{$data->customer_cnpj}%"); // create the filter
- TSession::setValue('ProspeccaoList_filter_customer_cnpj', $filter); // stores the filter in the session
- }
- if (isset($data->rasocial) AND ($data->rasocial)) {
- $filter = new TFilter('rasocial', 'like', "%{$data->rasocial}%"); // create the filter
- TSession::setValue('ProspeccaoList_filter_rasocial', $filter); // stores the filter in the session
- }
- if (isset($data->acompanhar) AND ($data->acompanhar)) {
- $filter = new TFilter('acompanhar', 'like', "%{$data->acompanhar}%"); // create the filter
- TSession::setValue('ProspeccaoList_filter_acompanhar', $filter); // stores the filter in the session
- }
- if (isset($data->proximocontato) AND ($data->proximocontato)) {
- $filter = new TFilter('proximocontato', 'like', "%{$data->proximocontato}%"); // create the filter
- TSession::setValue('ProspeccaoList_filter_proximocontato', $filter); // stores the filter in the session
- }
- // fill the form with data again
- $this->form->setData($data);
- // keep the search data in the session
- TSession::setValue('Prospeccao_filter_data', $data);
- $param=array();
- $param['offset'] =0;
- $param['first_page']=1;
- $this->onReload($param);
- }
- /**
- * Load the datagrid with data
- */
- public function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'samples'
- TTransaction::open('samples');
- // creates a repository for Prospeccao
- $repository = new TRepository('Prospeccao');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('ProspeccaoList_filter_customer_cnpj')) {
- $criteria->add(TSession::getValue('ProspeccaoList_filter_customer_cnpj')); // add the session filter
- }
- if (TSession::getValue('ProspeccaoList_filter_rasocial')) {
- $criteria->add(TSession::getValue('ProspeccaoList_filter_rasocial')); // add the session filter
- }
- if (TSession::getValue('ProspeccaoList_filter_acompanhar')) {
- $criteria->add(TSession::getValue('ProspeccaoList_filter_acompanhar')); // add the session filter
- }
- if (TSession::getValue('ProspeccaoList_filter_proximocontato')) {
- $criteria->add(TSession::getValue('ProspeccaoList_filter_proximocontato')); // add the session filter
- }
- // load the objects according to criteria
- $objects = $repository->load($criteria, FALSE);
- if (is_callable($this->transformCallback))
- {
- call_user_func($this->transformCallback, $objects, $param);
- }
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count= $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- /**
- * Ask before deletion
- */
- public function onDelete($param)
- {
- // define the delete action
- $action = new TAction(array($this, 'Delete'));
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * Delete a record
- */
- public function Delete($param)
- {
- try
- {
- $key=$param['key']; // get the parameter $key
- TTransaction::open('samples'); // open a transaction with database
- $object = new Prospeccao($key, FALSE); // instantiates the Active Record
- $object->delete(); // deletes the object from the database
- TTransaction::close(); // close the transaction
- $this->onReload( $param ); // reload the listing
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted')); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * method show()
- * Shows the page
- */
- public function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'], array('onReload', 'onSearch')))) )
- {
- if (func_num_args() > 0)
- {
- $this->onReload( func_get_arg(0) );
- }
- else
- {
- $this->onReload();
- }
- }
- parent::show();
- }
- }
Simples, fácil e rápido.. kkkkk
no onReload
Abraços
Funcionou perfeitamente, muito obrigado, testado e ajustado.
Uma maneira mais simples, sem precisar reescrever o onReload():
www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra