Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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 ...
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
  1. <?php
  2. /**
  3.  * ContaAPagarList Listing
  4.  * @author  <your name here>
  5.  */
  6. class ContaAPagarList 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_ContaAPagar');
  25.         $this->form->class 'tform'// change CSS class
  26.         $this->form = new BootstrapFormWrapper($this->form);
  27.         $this->form->style 'display: table;width:100%'// change style
  28.         $this->form->setFormTitle('ContaAPagar');
  29.         
  30.         // create the form fields
  31.      //   $id = new TEntry('id');
  32.          $titularidade_id = new TDBCombo('titularidade_id''sample''Titularidade''id','identificacao','identificacao asc');
  33.         $date_insert_ini = new TDate('date_insert_ini');
  34.         $date_insert_end = new TDate('date_insert_end');
  35.         $vencimento_ini = new TDate('vencimento_ini');
  36.         $vencimento_end = new TDate('vencimento_end');
  37.         $natureza_id = new TDBCombo('natureza_id','sample','Natureza','id','identificacao');
  38.         $valor_total = new TNumeric('valor_total','2',',','.');
  39.         $fornecedor_id = new TDBUniqueSearch('fornecedor_id','sample','Fornecedor','id','identificacao');
  40.         // add the fields
  41.       //  $this->form->addQuickField('Id', $id,  '100%' );
  42.         $this->form->addQuickField('Titularidade'$titularidade_id,  '100%' );
  43.         $this->form->addQuickField('Natureza'$natureza_id,  '100%' );
  44.         $this->form->addQuickField('Data de Inserção(Ini)'$date_insert_ini,  '100%' );
  45.         $this->form->addQuickField('Data de Inserção(Até)'$date_insert_end,  '100%' );
  46.         $this->form->addQuickField('Vencimento (Ini)'$vencimento_ini,  '100%' );
  47.         $this->form->addQuickField('Vencimento (Até)'$vencimento_end,  '100%' );
  48.         $this->form->addQuickField('Fornecedor'$fornecedor_id,  '100%' );
  49.         $this->form->setFieldsByRow(2);
  50.          //seting mask
  51.         $date_insert_ini->setDatabaseMask('yyyy-mm-dd');
  52.         $date_insert_end->setDatabaseMask('yyyy-mm-dd');
  53.         $date_insert_ini->setMask('dd/mm/yyyy');
  54.         $date_insert_end->setMask('dd/mm/yyyy');
  55.         $vencimento_ini->setDatabaseMask('yyyy-mm-dd');
  56.         $vencimento_end->setDatabaseMask('yyyy-mm-dd');
  57.         $vencimento_ini->setMask('dd/mm/yyyy');
  58.         $vencimento_end->setMask('dd/mm/yyyy');
  59.         //set size and other things
  60.         $fornecedor_id->setMinLength(1);
  61.         
  62.         // keep the form filled during navigation with session data
  63.         $this->form->setDataTSession::getValue('ContaAPagar_filter_data') );
  64.         
  65.         // add the search form actions
  66.         $btn $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  67.         $btn->class 'btn btn-sm btn-primary';
  68.         $this->form->addQuickAction(_t('New'),  new TAction(array('ContaAPagarForm''onEdit')), 'bs:plus-sign green');
  69.           $this->form->addQuickAction('Limpar formulário de Busca', new TAction([$this'onClear']), 'fa:eraser #dd5a43');
  70.         $btn->class 'btn btn-sm btn-primary';
  71.        
  72.         
  73.         
  74.         // creates a Datagrid
  75.         $this->datagrid = new TDataGrid;
  76.         $this->datagrid = new BootstrapDatagridWrapper($this->datagrid);
  77.         $this->datagrid->style 'width: 100%';
  78.       //  $this->datagrid->datatable = 'true';
  79.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  80.         
  81.         // creates the datagrid columns
  82.       //  $column_id = new TDataGridColumn('id', 'Id', 'right');
  83.       $column_numero_parcela = new TDataGridColumn('numero_parcela''Nº Vencimento''right');
  84.        $column_valor_parcela = new TDataGridColumn('valor_parcela''Valor''right');
  85.        $column_valor_parcela->setTransformer(array($this,'setValuebr' ));
  86.        $column_vencimento = new TDataGridColumn('vencimento''Vencimento''right');
  87.        $column_vencimento->setTransformer(array($this,'setDatebr'));
  88.       $column_conta_a_pagar_id = new TDataGridColumn('conta_a_pagar_id','Conta','center');
  89.         // add the columns to the DataGrid
  90.       //  $this->datagrid->addColumn($column_id);
  91.       $this->datagrid->addColumn($column_numero_parcela);
  92.         $this->datagrid->addColumn($column_valor_parcela);
  93.         $this->datagrid->addColumn($column_vencimento);
  94.        $this->datagrid->setGroupColumn('conta_a_pagar_id''<b>Fornecedor</b>: <i>{conta_a_pagar->fornecedor->identificacao}</i>&nbsp|&nbsp<b>Natureza</b>: <i>{conta_a_pagar->natureza->identificacao}</i>&nbsp|&nbsp<b>Valor Total</b>: <i>{conta_a_pagar->valor_total}</i>');
  95.     
  96.        
  97.   
  98.           
  99.         // create EDIT action
  100.         $action_edit = new TDataGridAction(array('ContaAPagarFormView''onShow'));
  101.         //$action_edit->setUseButton(FALSE);
  102.         //$action_edit->setButtonClass('btn btn-default');
  103.         //$action_edit->setLabel(_t('Edit'));
  104.        // $action_edit->setImage('fa:eye blue fa-lg');
  105.         $action_edit->setField('conta_a_pagar_id');
  106.         $this->datagrid->addAction($action_edit);
  107.        /* 
  108.         // create DELETE action
  109.         $action_del = new TDataGridAction(array($this, 'onDelete'));
  110.         //$action_del->setUseButton(TRUE);
  111.         //$action_del->setButtonClass('btn btn-default');
  112.         $action_del->setLabel(_t('Delete'));
  113.         $action_del->setImage('fa:trash-o red fa-lg');
  114.         $action_del->setField('id');
  115.         $this->datagrid->addAction($action_del);
  116.      */   
  117.         // create the datagrid model
  118.         $this->datagrid->createModel();
  119.         
  120.         // creates the page navigation
  121.         $this->pageNavigation = new TPageNavigation;
  122.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  123.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  124.         
  125.         // vertical box container
  126.         $container = new TVBox;
  127.         $container->style 'width: 90%';
  128.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  129.         $container->add(TPanelGroup::pack('Contas a Pagar'$this->form));
  130.         $container->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation));
  131.         
  132.         parent::add($container);
  133.     }
  134.     
  135.     /**
  136.      * Inline record editing
  137.      * @param $param Array containing:
  138.      *              key: object ID value
  139.      *              field name: object attribute to be updated
  140.      *              value: new attribute content 
  141.      */
  142.     public function onInlineEdit($param)
  143.     {
  144.         try
  145.         {
  146.             // get the parameter $key
  147.             $field $param['field'];
  148.             $key   $param['key'];
  149.             $value $param['value'];
  150.             
  151.             TTransaction::open('sample'); // open a transaction with database
  152.             $object = new ContaAPagar($key); // instantiates the Active Record
  153.             $object->{$field} = $value;
  154.             $object->store(); // update the object in the database
  155.             TTransaction::close(); // close the transaction
  156.             
  157.             $this->onReload($param); // reload the listing
  158.             new TMessage('info'"Record Updated");
  159.         }
  160.         catch (Exception $e// in case of exception
  161.         {
  162.             new TMessage('error'$e->getMessage()); // shows the exception error message
  163.             TTransaction::rollback(); // undo all pending operations
  164.         }
  165.     }
  166.     
  167.     public function setDatebr($data,$obj) {
  168.         $dt = new DateTime($data);
  169.         return $dt->format('d/m/Y');
  170.     }
  171.      public function setValuebr($valor)
  172.         {
  173.             $number number_format($valor,2,',','.');
  174.             return $number;
  175.         }
  176.       public function onClear() {
  177.        $this->form->clear();
  178.         TSession::setValue('object',null);
  179.         TSession::setValue('data',null);
  180.         $this->onReload();
  181.     }
  182.     /**
  183.      * Register the filter in the session
  184.      */
  185.     public function onSearch()
  186.     {
  187.         // get the search form data
  188.         $data $this->form->getData();
  189.         
  190.         // clear session filters
  191.         TSession::setValue('ContaAPagarList_filter_id',   NULL);
  192.         TSession::setValue('ContaAPagarList_filter_titularidade_id',   NULL);
  193.         TSession::setValue('ContaAPagarList_filter_identificacao',   NULL);
  194.         TSession::setValue('ContaAPagarList_filter_descricao',   NULL);
  195.         TSession::setValue('ContaAPagarList_filter_date_insert_ini',   NULL);
  196.         TSession::setValue('ContaAPagarList_filter_date_insert_end',   NULL);
  197.         TSession::setValue('ContaAPagarList_filter_vencimento_ini',   NULL);
  198.         TSession::setValue('ContaAPagarList_filter_vencimento_end',   NULL);
  199.         TSession::setValue('ContaAPagarList_filter_natureza_id',   NULL);
  200.         TSession::setValue('ContaAPagarList_filter_fornecedor_id',   NULL);
  201.         if (isset($data->id) AND ($data->id)) {
  202.             $filter = new TFilter('id''like'"%{$data->id}%"); // create the filter
  203.             TSession::setValue('ContaAPagarList_filter_id',   $filter); // stores the filter in the session
  204.         }
  205.         if (isset($data->titularidade_id) AND ($data->titularidade_id)) {
  206.             $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
  207.             TSession::setValue('ContaAPagarList_filter_titularidade_id',   $filter); // stores the filter in the session
  208.         }
  209.         if (isset($data->date_insert_ini) AND ($data->date_insert_ini)) {
  210.             $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
  211.             TSession::setValue('ContaAPagarList_filter_date_insert_ini',   $filter); // stores the filter in the session
  212.         }
  213.           if (isset($data->date_insert_end) AND ($data->date_insert_end)) {
  214.             $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
  215.             TSession::setValue('ContaAPagarList_filter_date_insert_end',   $filter); // stores the filter in the session
  216.         }
  217.         if (isset($data->vencimento_ini) AND ($data->vencimento_ini)) {
  218.             $filter = new TFilter('vencimento''>='$data->vencimento_ini); // create the filter
  219.             TSession::setValue('ContaAPagarList_filter_vencimento_ini',   $filter); // stores the filter in the session
  220.         }
  221.           if (isset($data->vencimento_end) AND ($data->vencimento_end)) {
  222.             $filter = new TFilter('vencimento''<='$data->vencimento_end); // create the filter
  223.             TSession::setValue('ContaAPagarList_filter_vencimento_end',   $filter); // stores the filter in the session
  224.         }
  225.         if (isset($data->natureza_id) AND ($data->natureza_id)) {
  226.             $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
  227.             TSession::setValue('ContaAPagarList_filter_natureza_id',   $filter); // stores the filter in the session
  228.         }
  229.         if (isset($data->fornecedor_id) AND ($data->fornecedor_id)) {
  230.             $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
  231.             TSession::setValue('ContaAPagarList_filter_fornecedor_id',   $filter); // stores the filter in the session
  232.         }
  233.         
  234.         // fill the form with data again
  235.         $this->form->setData($data);
  236.         
  237.         // keep the search data in the session
  238.         TSession::setValue('ContaAPagar_filter_data'$data);
  239.         
  240.         $param=array();
  241.         $param['offset']    =0;
  242.         $param['first_page']=1;
  243.         $this->onReload($param);
  244.     }
  245.     
  246.     /**
  247.      * Load the datagrid with data
  248.      */
  249.     public function onReload($param NULL)
  250.     {
  251.         try
  252.         {
  253.             // open a transaction with database 'sample'
  254.             TTransaction::open('sample');
  255.             
  256.             // creates a repository for Parcelas
  257.             $repository = new TRepository('Parcela');
  258.             $limit 10;
  259.             // creates a criteria
  260.             $criteria = new TCriteria;
  261.             
  262.             // default order
  263.             if (empty($param['order']))
  264.             {
  265.              $param['order'] = 'vencimento';
  266.                 $param['direction'] = 'asc';
  267.             }
  268.             $criteria->setProperties($param); // order, offset
  269.             $criteria->setProperty('limit'$limit);
  270.             
  271.             if (TSession::getValue('ContaAPagarList_filter_id')) {
  272.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_id')); // add the session filter
  273.             }
  274.             if (TSession::getValue('ContaAPagarList_filter_titularidade_id')) {
  275.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_titularidade_id')); // add the session filter
  276.             }
  277.             if (TSession::getValue('ContaAPagarList_filter_identificacao')) {
  278.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_identificacao')); // add the session filter
  279.             }
  280.             if (TSession::getValue('ContaAPagarList_filter_descricao')) {
  281.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_descricao')); // add the session filter
  282.             }
  283.             if (TSession::getValue('ContaAPagarList_filter_date_insert_ini')) {
  284.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_date_insert_ini')); // add the session filter
  285.             }
  286.              if (TSession::getValue('ContaAPagarList_filter_date_insert_end')) {
  287.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_date_insert_end')); // add the session filter
  288.             }
  289.             if (TSession::getValue('ContaAPagarList_filter_vencimento_ini')) {
  290.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_vencimento_ini')); // add the session filter
  291.             }
  292.             if (TSession::getValue('ContaAPagarList_filter_vencimento_end')) {
  293.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_vencimento_end')); // add the session filter
  294.             }
  295.             if (TSession::getValue('ContaAPagarList_filter_natureza_id')) {
  296.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_natureza_id')); // add the session filter
  297.             }
  298.             if (TSession::getValue('ContaAPagarList_filter_valor_total')) {
  299.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_valor_total')); // add the session filter
  300.             }
  301.             if (TSession::getValue('ContaAPagarList_filter_fornecedor_id')) {
  302.                 $criteria->add(TSession::getValue('ContaAPagarList_filter_fornecedor_id')); // add the session filter
  303.             }
  304.             
  305.             // load the objects according to criteria
  306.             $objects $repository->load($criteriaFALSE);
  307.             
  308.             if (is_callable($this->transformCallback))
  309.             {
  310.                 call_user_func($this->transformCallback$objects$param);
  311.             }
  312.             
  313.             $this->datagrid->clear();
  314.             if ($objects)
  315.             {
  316.                 // iterate the collection of active records
  317.                 foreach ($objects as $object)
  318.                 {
  319.                     // add the object inside the datagrid
  320.                     $this->datagrid->addItem($object);
  321.                     
  322.                 }
  323.             }
  324.             
  325.             // reset the criteria for record count
  326.             $criteria->resetProperties();
  327.             $count$repository->count($criteria);
  328.             
  329.             $this->pageNavigation->setCount($count); // count of records
  330.             $this->pageNavigation->setProperties($param); // order, page
  331.             $this->pageNavigation->setLimit($limit); // limit
  332.             
  333.             // close the transaction
  334.             TTransaction::close();
  335.             $this->loaded true;
  336.         }
  337.         catch (Exception $e// in case of exception
  338.         {
  339.             // shows the exception error message
  340.             new TMessage('error'$e->getMessage());
  341.             // undo all pending operations
  342.             TTransaction::rollback();
  343.         }
  344.     }
  345.     
  346.     /**
  347.      * Ask before deletion
  348.      */
  349.     public function onDelete($param)
  350.     {
  351.         // define the delete action
  352.         $action = new TAction(array($this'Delete'));
  353.         $action->setParameters($param); // pass the key parameter ahead
  354.         // shows a dialog to the user
  355.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  356.     }
  357.     
  358.     /**
  359.      * Delete a record
  360.      */
  361.     public function Delete($param)
  362.     {
  363.         try
  364.         {
  365.             $key=$param['key']; // get the parameter $key
  366.             TTransaction::open('sample'); // open a transaction with database
  367.             $object = new ContaAPagar($keyFALSE); // instantiates the Active Record
  368.             $object->delete(); // deletes the object from the database
  369.             TTransaction::close(); // close the transaction
  370.             $this->onReload$param ); // reload the listing
  371.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted')); // success message
  372.         }
  373.         catch (Exception $e// in case of exception
  374.         {
  375.             new TMessage('error'$e->getMessage()); // shows the exception error message
  376.             TTransaction::rollback(); // undo all pending operations
  377.         }
  378.     }
  379.     
  380.     
  381.     /**
  382.      * method show()
  383.      * Shows the page
  384.      */
  385.     public function show()
  386.     {
  387.         // check if the datagrid is already loaded
  388.         if (!$this->loaded AND (!isset($_GET['method']) OR !(in_array($_GET['method'],  array('onReload''onSearch')))) )
  389.         {
  390.             if (func_num_args() > 0)
  391.             {
  392.                 $this->onReloadfunc_get_arg(0) );
  393.             }
  394.             else
  395.             {
  396.                 $this->onReload();
  397.             }
  398.         }
  399.      
  400.         parent::show();
  401.     }
  402. }
  403. </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


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


NR

Você pode adicionar o html diretamente, como já está fazendo com algumas tags().

Também é possível usar um componente e pegar seu html:
  1. <?php
  2. $actionLink = new TActionLink('Acao',new TAction([$this,'onAction'],['key'=>'nome_coluna'])); // nome_coluna é o identificador necessário para saber qual grupo excluir, pode colocar outro nome se quiser
  3. $actionLink->class 'btn btn-default';
  4. $htmlAction $actionLink->getContents();
  5. $htmlAction str_replace('nome_coluna','{conta_a_pagar_id}',$htmlAction); // fazer o replace do "nome_coluna" pela coluna correspondente do banco de dados
  6.         
  7. // define the group column and group mask pattern
  8. $this->datagrid->setGroupColumn('conta_a_pagar_id'$htmlAction);
  9. ?>
TC

Funcionou Perfeito Nataniel, Obrigado!