TC
botão delete no setGroupColumn
Senhores quero colocar um botão de delete no agrupamento da coluna conta_a_pagar_id, alguém já colocou um botão usando a função setGroupColumn ?
segue a baixo minha class
segue a baixo minha class
- <?php
- /**
- * ContaAPagarList Listing
- * @author <your name here>
- */
- class ContaAPagarList 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_ContaAPagar');
- $this->form->class = 'tform'; // change CSS class
- $this->form = new BootstrapFormWrapper($this->form);
- $this->form->style = 'display: table;width:100%'; // change style
- $this->form->setFormTitle('ContaAPagar');
- // create the form fields
- // $id = new TEntry('id');
- $titularidade_id = new TDBCombo('titularidade_id', 'sample', 'Titularidade', 'id','identificacao','identificacao asc');
- $date_insert_ini = new TDate('date_insert_ini');
- $date_insert_end = new TDate('date_insert_end');
- $vencimento_ini = new TDate('vencimento_ini');
- $vencimento_end = new TDate('vencimento_end');
- $natureza_id = new TDBCombo('natureza_id','sample','Natureza','id','identificacao');
- $valor_total = new TNumeric('valor_total','2',',','.');
- $fornecedor_id = new TDBUniqueSearch('fornecedor_id','sample','Fornecedor','id','identificacao');
- // add the fields
- // $this->form->addQuickField('Id', $id, '100%' );
- $this->form->addQuickField('Titularidade', $titularidade_id, '100%' );
- $this->form->addQuickField('Natureza', $natureza_id, '100%' );
- $this->form->addQuickField('Data de Inserção(Ini)', $date_insert_ini, '100%' );
- $this->form->addQuickField('Data de Inserção(Até)', $date_insert_end, '100%' );
- $this->form->addQuickField('Vencimento (Ini)', $vencimento_ini, '100%' );
- $this->form->addQuickField('Vencimento (Até)', $vencimento_end, '100%' );
- $this->form->addQuickField('Fornecedor', $fornecedor_id, '100%' );
- $this->form->setFieldsByRow(2);
- //seting mask
- $date_insert_ini->setDatabaseMask('yyyy-mm-dd');
- $date_insert_end->setDatabaseMask('yyyy-mm-dd');
- $date_insert_ini->setMask('dd/mm/yyyy');
- $date_insert_end->setMask('dd/mm/yyyy');
- $vencimento_ini->setDatabaseMask('yyyy-mm-dd');
- $vencimento_end->setDatabaseMask('yyyy-mm-dd');
- $vencimento_ini->setMask('dd/mm/yyyy');
- $vencimento_end->setMask('dd/mm/yyyy');
- //set size and other things
- $fornecedor_id->setMinLength(1);
- // keep the form filled during navigation with session data
- $this->form->setData( TSession::getValue('ContaAPagar_filter_data') );
- // add the search form actions
- $btn = $this->form->addQuickAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');
- $btn->class = 'btn btn-sm btn-primary';
- $this->form->addQuickAction(_t('New'), new TAction(array('ContaAPagarForm', 'onEdit')), 'bs:plus-sign green');
- $this->form->addQuickAction('Limpar formulário de Busca', new TAction([$this, 'onClear']), 'fa:eraser #dd5a43');
- $btn->class = 'btn btn-sm btn-primary';
- // creates a Datagrid
- $this->datagrid = new TDataGrid;
- $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
- $this->datagrid->style = 'width: 100%';
- // $this->datagrid->datatable = 'true';
- // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- // creates the datagrid columns
- // $column_id = new TDataGridColumn('id', 'Id', 'right');
- $column_numero_parcela = new TDataGridColumn('numero_parcela', 'Nº Vencimento', 'right');
- $column_valor_parcela = new TDataGridColumn('valor_parcela', 'Valor', 'right');
- $column_valor_parcela->setTransformer(array($this,'setValuebr' ));
- $column_vencimento = new TDataGridColumn('vencimento', 'Vencimento', 'right');
- $column_vencimento->setTransformer(array($this,'setDatebr'));
- $column_conta_a_pagar_id = new TDataGridColumn('conta_a_pagar_id','Conta','center');
- // add the columns to the DataGrid
- // $this->datagrid->addColumn($column_id);
- $this->datagrid->addColumn($column_numero_parcela);
- $this->datagrid->addColumn($column_valor_parcela);
- $this->datagrid->addColumn($column_vencimento);
- $this->datagrid->setGroupColumn('conta_a_pagar_id', '<b>Fornecedor</b>: <i>{conta_a_pagar->fornecedor->identificacao}</i> | <b>Natureza</b>: <i>{conta_a_pagar->natureza->identificacao}</i> | <b>Valor Total</b>: <i>{conta_a_pagar->valor_total}</i>');
- // create EDIT action
- $action_edit = new TDataGridAction(array('ContaAPagarFormView', 'onShow'));
- //$action_edit->setUseButton(FALSE);
- //$action_edit->setButtonClass('btn btn-default');
- //$action_edit->setLabel(_t('Edit'));
- // $action_edit->setImage('fa:eye blue fa-lg');
- $action_edit->setField('conta_a_pagar_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());
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add(TPanelGroup::pack('Contas a Pagar', $this->form));
- $container->add(TPanelGroup::pack('', $this->datagrid, $this->pageNavigation));
- parent::add($container);
- }
- /**
- * 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('sample'); // open a transaction with database
- $object = new ContaAPagar($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', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- public function setDatebr($data,$obj) {
- $dt = new DateTime($data);
- return $dt->format('d/m/Y');
- }
- public function setValuebr($valor)
- {
- $number = number_format($valor,2,',','.');
- return $number;
- }
- public function onClear() {
- $this->form->clear();
- TSession::setValue('object',null);
- TSession::setValue('data',null);
- $this->onReload();
- }
- /**
- * Register the filter in the session
- */
- public function onSearch()
- {
- // get the search form data
- $data = $this->form->getData();
- // clear session filters
- TSession::setValue('ContaAPagarList_filter_id', NULL);
- TSession::setValue('ContaAPagarList_filter_titularidade_id', NULL);
- TSession::setValue('ContaAPagarList_filter_identificacao', NULL);
- TSession::setValue('ContaAPagarList_filter_descricao', NULL);
- TSession::setValue('ContaAPagarList_filter_date_insert_ini', NULL);
- TSession::setValue('ContaAPagarList_filter_date_insert_end', NULL);
- TSession::setValue('ContaAPagarList_filter_vencimento_ini', NULL);
- TSession::setValue('ContaAPagarList_filter_vencimento_end', NULL);
- TSession::setValue('ContaAPagarList_filter_natureza_id', NULL);
- TSession::setValue('ContaAPagarList_filter_fornecedor_id', NULL);
- if (isset($data->id) AND ($data->id)) {
- $filter = new TFilter('id', 'like', "%{$data->id}%"); // create the filter
- TSession::setValue('ContaAPagarList_filter_id', $filter); // stores the filter in the session
- }
- if (isset($data->titularidade_id) AND ($data->titularidade_id)) {
- $filter = new TFilter('(SELECT titularidade_id FROM conta_a_pagar WHERE conta_a_pagar_id = conta_a_pagar.id )', 'like', "%{$data->titularidade_id}%"); // create the filter
- TSession::setValue('ContaAPagarList_filter_titularidade_id', $filter); // stores the filter in the session
- }
- if (isset($data->date_insert_ini) AND ($data->date_insert_ini)) {
- $filter = new TFilter('(SELECT date_insert FROM conta_a_pagar WHERE conta_a_pagar_id = conta_a_pagar.id)', '>=', $data->date_insert_ini); // create the filter
- TSession::setValue('ContaAPagarList_filter_date_insert_ini', $filter); // stores the filter in the session
- }
- if (isset($data->date_insert_end) AND ($data->date_insert_end)) {
- $filter = new TFilter('(SELECT date_insert FROM conta_a_pagar WHERE conta_a_pagar_id = conta_a_pagar.id)', '<=', $data->date_insert_end); // create the filter
- TSession::setValue('ContaAPagarList_filter_date_insert_end', $filter); // stores the filter in the session
- }
- if (isset($data->vencimento_ini) AND ($data->vencimento_ini)) {
- $filter = new TFilter('vencimento', '>=', $data->vencimento_ini); // create the filter
- TSession::setValue('ContaAPagarList_filter_vencimento_ini', $filter); // stores the filter in the session
- }
- if (isset($data->vencimento_end) AND ($data->vencimento_end)) {
- $filter = new TFilter('vencimento', '<=', $data->vencimento_end); // create the filter
- TSession::setValue('ContaAPagarList_filter_vencimento_end', $filter); // stores the filter in the session
- }
- if (isset($data->natureza_id) AND ($data->natureza_id)) {
- $filter = new TFilter('(SELECT natureza_id FROM conta_a_pagar WHERE conta_a_pagar_id = conta_a_pagar.id)', '=', $data->natureza_id); // create the filter
- TSession::setValue('ContaAPagarList_filter_natureza_id', $filter); // stores the filter in the session
- }
- if (isset($data->fornecedor_id) AND ($data->fornecedor_id)) {
- $filter = new TFilter('(SELECT fornecedor_id FROM conta_a_pagar WHERE conta_a_pagar_id = conta_a_pagar.id)', '=', $data->fornecedor_id); // create the filter
- TSession::setValue('ContaAPagarList_filter_fornecedor_id', $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('ContaAPagar_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 'sample'
- TTransaction::open('sample');
- // creates a repository for Parcelas
- $repository = new TRepository('Parcela');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'vencimento';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- if (TSession::getValue('ContaAPagarList_filter_id')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_id')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_titularidade_id')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_titularidade_id')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_identificacao')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_identificacao')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_descricao')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_descricao')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_date_insert_ini')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_date_insert_ini')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_date_insert_end')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_date_insert_end')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_vencimento_ini')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_vencimento_ini')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_vencimento_end')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_vencimento_end')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_natureza_id')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_natureza_id')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_valor_total')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_valor_total')); // add the session filter
- }
- if (TSession::getValue('ContaAPagarList_filter_fornecedor_id')) {
- $criteria->add(TSession::getValue('ContaAPagarList_filter_fornecedor_id')); // 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('sample'); // open a transaction with database
- $object = new ContaAPagar($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();
- }
- }
- </code
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
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4
Quero me inscrever agora!
Você pode adicionar o html diretamente, como já está fazendo com algumas tags().
Também é possível usar um componente e pegar seu html:
Funcionou Perfeito Nataniel, Obrigado!