Lançado Adianti Framework 7.6!
Clique aqui para saber mais
function onSearch() , buscar em varias colunas do datagrid. Boa tarde, Gostaria de uma ajudar sou um pouco leigo em desenvolvimento. e gostaria de fazer um campo buscar no datagrid, onde ele busque dados de varias colunas do datagrid carregado. Queria usar o campo buscar, para buscar exemplo do meu codigo logo abaixo, Buscar: $col_cliente ou $col_task. e Buscar de mais de um campo Ex: Cliente, Task, Data Inicial. Poderiam me ajudar como deveria ...
MS
function onSearch() , buscar em varias colunas do datagrid.  
Boa tarde,
Gostaria de uma ajudar sou um pouco leigo em desenvolvimento.
e gostaria de fazer um campo buscar no datagrid, onde ele busque dados de varias colunas do datagrid carregado.

Queria usar o campo buscar, para buscar exemplo do meu codigo logo abaixo, Buscar: $col_cliente ou $col_task.

e Buscar de mais de um campo Ex: Cliente, Task, Data Inicial.

Poderiam me ajudar como deveria fazer isso em meu codigo?

Agradeço desde já.

  1. <?php
  2. class ChangeGrid extends TPage
  3. {
  4.     private $form;
  5.     private $datagrid;
  6.     private $pageNavigation;
  7.     private    $loaded;
  8.            
  9.     public function __construct()
  10.     {
  11.         parent::__construct();
  12.           
  13.         
  14.         // creates the form
  15.         $this->form = new BootstrapFormBuilder('form_search_City');
  16.         $this->form->setFormTitle('Standard DataGrid');
  17.         
  18.         $buscar = new TEntry('buscar');
  19.         $this->form->addFields( [new TLabel('Buscar:')], [$buscar] );
  20.         
  21.         // add form actions
  22.         $this->form->addAction('Find', new TAction([$this'onSearch']), 'fa:search blue');
  23.         $this->form->addActionLink('New',  new TAction(['ChangeForm','onClear']), 'fa:plus-circle green');
  24.         $this->form->addActionLink('Clear',  new TAction([$this'clear']), 'fa:eraser red');
  25.         
  26.         // keep the form filled with the search data
  27.         $this->form->setDataTSession::getValue('onSearch'));
  28.                      
  29.         // creates one datagrid
  30.         $this->datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
  31.         //$this->datagrid->style = 'min-width: 1600px';              
  32.         $this->datagrid->width "100%";
  33.        
  34.         $col_cliente    = new TDataGridColumn('cliente''Cliente''center''10%');
  35.         $col_change = new TDataGridColumn('change_id''Change''left','10%');
  36.         $col_task = new TDataGridColumn('task_id''Task''left','10%');
  37.         $col_hostaname = new TDataGridColumn('hostnames''Hostname''left','10%');
  38.         $col_data_inicial = new TDataGridColumn'data_change_inicial''Data Inicial''left','10%');
  39.         $col_data_final = new TDataGridColumn('data_change_final''Data Final''left','10%');
  40.         $col_atividade = new TDataGridColumn('atividade''Atividade''left','10%');
  41.         $col_st_atividade = new TDataGridColumn('status_atividade''Status de Atividade''left','10%');
  42.         $col_st_change = new TDataGridColumn('status_change''Status da Change''left','10%');
  43.         $col_coord = new TDataGridColumn('coordinator''Coordinator''left','10%');
  44.        
  45.         // add the columns
  46.         
  47.         $this->datagrid->addColumn($col_cliente);
  48.         $this->datagrid->addColumn($col_change);
  49.         $this->datagrid->addColumn($col_task);
  50.         $this->datagrid->addColumn($col_hostaname);
  51.         $this->datagrid->addColumn($col_data_inicial);
  52.         $this->datagrid->addColumn($col_data_final);
  53.         $this->datagrid->addColumn($col_atividade);
  54.         $this->datagrid->addColumn($col_st_atividade);
  55.         $this->datagrid->addColumn($col_st_change);
  56.         $this->datagrid->addColumn($col_coord);
  57.         
  58.         $col_cliente->setAction( new TAction([$this'onReload']),   ['order' => 'cliente']);
  59.         $col_do_im->setAction( new TAction([$this'onReload']), ['order' => 'id_do_im']);
  60.               
  61.         $edit = new TDataGridAction(array ('ChangeForm''onEdit'));
  62.         $this->datagrid->addQuickAction('Editar'$edit'id''ico_edit.png'); 
  63.                         
  64.         // creates the datagrid model
  65.         $this->datagrid->createModel();            
  66.               
  67.         $this->pageNavigation = new TPageNavigation;
  68.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));  
  69.         $this->pageNavigation->setWidth($this->datagrid->getWidth());         
  70.       
  71.                 
  72.         // wrap the page content using vertical box
  73.         $vbox = new TVBox;
  74.         $vbox->style 'width: 100%';
  75.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  76.         //$vbox->add($panel);
  77.         $vbox->add($this->form);
  78.         $vbox->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation)); // add a row for page navigation
  79.         
  80.         TTransaction::close(); // close transaction
  81.         parent::add($vbox);
  82.     }
  83.        
  84.     /**
  85.      * Load the data into the datagrid
  86.      */
  87.     
  88.     public function onReload($param NULL)
  89.     {
  90.     try
  91.         {
  92.             TTransaction::open('sample');
  93.             
  94.             $repository = new TRepository('SystemChange');
  95.             $limit 10;
  96.             
  97.             $criteria = new TCriteria;
  98.             
  99.             if (empty($param['order']))
  100.             {
  101.                 $param['order'] = 'id';
  102.                 $param['directi'] = 'asc';
  103.             }
  104.             
  105.             $criteria->setProperties($param); // order, offset
  106.             $criteria->setProperty('limit'$limit);
  107.             
  108.             if (TSession::getValue('Find_filter'))
  109.             {
  110.                 // add the filter stored in the session to the criteria
  111.                 $criteria->add(TSession::getValue('Find_filter'));
  112.             }
  113.             
  114.             $objects $repository->load$criteria );
  115.             
  116.             $this->datagrid->clear();
  117.             
  118.             if ($objects)
  119.             {
  120.                 foreach($objects as $object)
  121.                 {
  122.                     $this->datagrid->addItem($object);
  123.                 }
  124.             }
  125.             $criteria->resetProperties();
  126.             $count $repository->count($criteria);
  127.             
  128.             $this->pageNavigation->setCount($count); // count of records
  129.             $this->pageNavigation->setProperties($param); // order, page
  130.             $this->pageNavigation->setLimit($limit); // limit
  131.                         
  132.             TTransaction::close();
  133.             $this->loaded true;
  134.         }
  135.         catch (Exception $e)
  136.         {
  137.             new TMessage('error'$e->getMessage());
  138.             TTransaction::rollback(); // undo all pending operations    
  139.         }
  140.         
  141.         $this->loaded TRUE;
  142.     }
  143.     function clear()
  144.     {
  145.         $this->form->clear();
  146.         $this->onReload();
  147.     }
  148.    
  149.     public function show()
  150.     {
  151.        if (!$this->loaded)
  152.        {
  153.            $this->onReloadfunc_get_arg(0) );
  154.        }
  155.        parent::show();
  156.     }
  157.     function onSearch()
  158.     {
  159.         // get the search form data
  160.         $data $this->form->getData($data);
  161.         
  162.         // check if the user has filled the form
  163.         if (isset($data->buscar))
  164.         {
  165.             // creates a filter using what the user has typed
  166.             $filter = new TFilter('buscar''like'"%{$data->buscar}%");
  167.             
  168.             // stores the filter in the session
  169.             TSession::setValue('Find_filter'$filter);
  170.             TSession::setValue('Buscar',   $data->buscar);
  171.             
  172.             // fill the form with data again
  173.             $this->form->setData($data);
  174.         }
  175.         
  176.         $param = array();
  177.         $param['offset']    =0;
  178.         $param['first_page']=1;
  179.         $this->onReload($param);
  180.     }
  181. }
  182. </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 (4)


NR

Em resumo a busca funciona assim: 1 - Ao clicar no botão Buscar vai para a função onSearch, que verifica os dados do formulário e salva essas informações na sessão. 2 - A função onReload, que é quem exibe as informações do banco de dados, verifica se há filtros na sessão para buscar os dados.

O caminho mais simples acredito que seja criar os vários filtros na função onSearch e agrupá-los em um criteria(fazendo um OR entre eles), sendo que esse criteria será salvo na sessão para ser utilizado como filtro principal:
  1. <?php
  2. //onSearch
  3. if (isset($data->buscar))
  4. {
  5.       // creates a filter using what the user has typed
  6.       $filter1 = new TFilter('buscar''like'"%{$data->buscar}%");
  7.       $filter2 = new TFilter('campo2''like'"%{$data->buscar}%");
  8.       $filter3 = new TFilter('campo3''like'"%{$data->buscar}%");
  9.       $crit = new TCriteria();
  10.       $crit->add($filter1,TExpression::OR_OPERATOR);
  11.       $crit->add($filter2,TExpression::OR_OPERATOR);
  12.       $crit->add($filter2,TExpression::OR_OPERATOR);
  13.       TSession::setValue('Find_filter'$crit);
  14. ?>
JP

Caríssimo Nataniel Rabaioli espero que estejas de bom animo.
Queira por favor me ajudar. Estou tentando fazer um relatório de venda, já tive iniciativa a partir das apostilas que adquiri ao comprar o pacote completo do Adiant Profissional.
No exemplo que está no livro mostra em DocumentHtmlPdfView e o PDFDesignReportView. Eu quero fazer com ambos, incluindo 2 tabelas ou mais. como é o caso de uma fatura de compra ou de venda entre as tabelas venda e itens da venda, apos o nome do produto, quantidade, total e o nome do cliente, tenha um button generate para gerar um relatorio em pdf.


Abaixo segue o formulario que pretendo que tenha um relatório.


  1. <?php
  2. /**
  3.  * VendaForm Master/Detail
  4.  * @author  <your name here>
  5.  */
  6. class VendaForm extends TPage
  7. {
  8.     protected $form// form
  9.     protected $detail_list;
  10.     
  11.     /**
  12.      * Page constructor
  13.      */
  14.     public function __construct()
  15.     {
  16.         parent::__construct();
  17.         
  18.         // creates the form
  19.         $this->form = new BootstrapFormBuilder('form_Venda');
  20.         $this->form->setFormTitle('Venda');
  21.         
  22.         // master fields
  23.         $ven_cod = new TEntry('ven_cod');
  24.         $cliente = new TEntry('cliente');
  25.         $cli_cod_fk = new TDBUniqueSearch('cli_cod_fk''bd_venda''Cliente''cli_cod''cli_nome');
  26.         // detail fields
  27.         $detail_itv_cod = new THidden('detail_itv_cod');
  28.         $detail_cod_prod = new TDBUniqueSearch('detail_cod_prod''bd_venda''Produto''pro_cod''pro_nome');
  29.         $detail_preco_venda = new TEntry('detail_preco_venda');
  30.         $detail_quantidade = new TEntry('detail_quantidade');
  31.        
  32.        
  33.         $detail_cod_prod->setChangeAction( new TAction([$this'onProductChange']));
  34.         if (!empty($ven_cod))
  35.         {
  36.             $ven_cod->setEditable(FALSE);
  37.         }
  38.         
  39.         // master fields
  40.         $this->form->addFields( [new TLabel('Código')], [$ven_cod] );
  41.         $this->form->addFields( [new TLabel('Cliente')], [$cliente] );
  42.         $this->form->addFields( [new TLabel('Cliente Fidelizado')], [$cli_cod_fk] );
  43.         
  44.         // detail fields
  45.         $this->form->addContent( ['<h4>Detalhes da Venda</h4><hr>'] );
  46.         $this->form->addFields( [$detail_itv_cod] );
  47.         
  48.         $this->form->addFields( [new TLabel('Produto')], [$detail_cod_prod] );
  49.         $this->form->addFields( [new TLabel('Preço ')], [$detail_preco_venda] );
  50.         $this->form->addFields( [new TLabel('Quantidade')], [$detail_quantidade] );
  51.        
  52.         $add TButton::create('add', [$this'onSaveDetail'], 'Register''fa:save');
  53.         $this->form->addFields( [], [$add] )->style 'background: whitesmoke; padding: 5px; margin: 1px;';
  54.         
  55.         $this->detail_list = new BootstrapDatagridWrapper(new TQuickGrid);
  56.         $this->detail_list->style "min-width: 700px; width:100%;margin-bottom: 10px";
  57.         $this->detail_list->setId('Venda_list');
  58.         
  59.         // items
  60.       $prod=   $this->detail_list->addQuickColumn('Produto''cod_prod''left'50);
  61.       $preco=  $this->detail_list->addQuickColumn('Preço ''preco_venda''left'30);
  62.         $this->detail_list->addQuickColumn('Quantidade''quantidade''left'30);
  63.       
  64.         
  65.         
  66.          //Calcula o total da datagrid
  67.         $subtotal $this->detail_list->addQuickColumn('Subtotal''={quantidade} *  {preco_venda}''right'50);
  68.    
  69.          //Converte o valor numerico em milhares
  70.         $format_value = function($value){
  71.             if  (is_numeric($value))
  72.             {
  73.                 return  'Kz '  .  number_format ($value,   2,   ' ,  ' ,  '  .  ');
  74.             }
  75.             return $value;
  76.         };
  77.         
  78.         $subtotal->setTransformer($format_value);
  79.         $preco->setTransformer($format_value);
  80.  
  81.        $subtotal->setTotalFunction(function($values){
  82.            return array_sum((array) $values);
  83.        });
  84.        
  85.        $prod-> setTransformer( function ($value)   {
  86.              return Produto :: findInTransaction 'bd_venda' ,  $value  )->pro_nome;
  87.        });
  88.         // detail actions
  89.         $this->detail_list->addQuickAction'Edit',   new TDataGridAction([$this'onEditDetail']),   'itv_cod''fa:edit blue');
  90.         $this->detail_list->addQuickAction'Delete', new TDataGridAction([$this'onDeleteDetail']), 'itv_cod''fa:trash red');
  91.         $this->detail_list->createModel();
  92.         
  93.         $panel = new TPanelGroup;
  94.         $panel->add($this->detail_list);
  95.         $panel->getBody()->style 'overflow-x:auto';
  96.         $this->form->addContent( [$panel] );
  97.         $btn $this->form->addAction_t('Save'),  new TAction([$this'onSave']), 'fa:save');
  98.         $btn->class 'btn btn-sm btn-primary';
  99.         $this->form->addAction_t('Clear'), new TAction([$this'onClear']), 'fa:eraser red');
  100.         
  101.         // create the page container
  102.         $container = new TVBox;
  103.         $container->style 'width: 100%';
  104.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  105.         $container->add($this->form);
  106.         parent::add($container);
  107.     }
  108.     
  109.      //METODO QUE BUSCA O PREÇO DO ITEM 
  110.     public static function onProductChange$params )
  111.     {
  112.         if(!empty($params['detail_cod_prod']))
  113.         {
  114.             try
  115.             {
  116.                 TTransaction :: open('bd_venda');
  117.                 
  118.                 $produto Produto :: find($params['detail_cod_prod']);
  119.                 $fill_data = new StdClass;
  120.                 $fill_data->detail_preco_venda  =  $produto->pro_preco;
  121.                 
  122.                 TForm :: sendData ('form_Venda'$fill_data);
  123.                 TTransaction::close();   
  124.             }
  125.             catch(Exception $e)
  126.             {
  127.                 new TMessage('error'$e->getMessage());
  128.                 TTransaction::rollback();
  129.             }
  130.         }
  131.     }
  132.  
  133.     /**
  134.      * Clear form
  135.      * @param $param URL parameters
  136.      */
  137.     public function onClear($param)
  138.     {
  139.         $this->form->clear(TRUE);
  140.         TSession::setValue(__CLASS__.'_items', array());
  141.         $this->onReload$param );
  142.     }
  143.     
  144.     /**
  145.      * Save an item from form to session list
  146.      * @param $param URL parameters
  147.      */
  148.     public function onSaveDetail$param )
  149.     {
  150.         try
  151.         {
  152.             TTransaction::open('bd_venda');
  153.             $data $this->form->getData();
  154.             
  155.             /** validation sample
  156.             if (empty($data->fieldX))
  157.             {
  158.                 throw new Exception('The field fieldX is required');
  159.             }
  160.             **/
  161.             
  162.             $items TSession::getValue(__CLASS__.'_items');
  163.             $key = empty($data->detail_itv_cod) ? 'X'.mt_rand(10000000001999999999) : $data->detail_itv_cod;
  164.             
  165.             $items$key ] = array();
  166.             $items$key ]['itv_cod'] = $key;
  167.             $items$key ]['cod_prod'] = $data->detail_cod_prod;
  168.             $items$key ]['preco_venda'] = $data->detail_preco_venda;
  169.             $items$key ]['quantidade'] = $data->detail_quantidade;
  170.           
  171.             
  172.             TSession::setValue(__CLASS__.'_items'$items);
  173.             
  174.             // clear detail form fields
  175.             $data->detail_itv_cod '';
  176.             $data->detail_cod_prod '';
  177.             $data->detail_preco_venda '';
  178.             $data->detail_quantidade '';
  179.           
  180.             
  181.             TTransaction::close();
  182.             $this->form->setData($data);
  183.             
  184.             $this->onReload$param ); // reload the items
  185.         }
  186.         catch (Exception $e)
  187.         {
  188.             $this->form->setData$this->form->getData());
  189.             new TMessage('error'$e->getMessage());
  190.         }
  191.         $this->form->clear(TRUE);  //Para Limpar os campos do formulario Mestre
  192.     }
  193.     
  194.     /**
  195.      * Load an item from session list to detail form
  196.      * @param $param URL parameters
  197.      */
  198.     public static function onEditDetail$param )
  199.     {
  200.         // read session items
  201.         $items TSession::getValue(__CLASS__.'_items');
  202.         
  203.         // get the session item
  204.         $item $items$param['key'] ];
  205.         
  206.         $data = new stdClass;
  207.         $data->detail_itv_cod $item['itv_cod'];
  208.         $data->detail_cod_prod $item['cod_prod'];
  209.         $data->detail_preco_venda $item['preco_venda'];
  210.         $data->detail_quantidade $item['quantidade'];
  211.       
  212.         
  213.         // fill detail fields
  214.         TForm::sendData'form_Venda'$data );
  215.     }
  216.     
  217.     /**
  218.      * Delete an item from session list
  219.      * @param $param URL parameters
  220.      */
  221.     public static function onDeleteDetail$param )
  222.     {
  223.         // reset items
  224.         $data = new stdClass;
  225.             $data->detail_cod_prod '';
  226.             $data->detail_preco_venda '';
  227.             $data->detail_quantidade '';
  228.             
  229.         
  230.         // clear form data
  231.         TForm::sendData('form_Venda'$data );
  232.         
  233.         // read session items
  234.         $items TSession::getValue(__CLASS__.'_items');
  235.         
  236.         // get detail id
  237.         $detail_id $param['key'];
  238.         
  239.         // delete the item from session
  240.         unset($items$detail_id ] );
  241.         
  242.         // rewrite session items
  243.         TSession::setValue(__CLASS__.'_items'$items);
  244.         
  245.         // delete item from screen
  246.         TScript::create("ttable_remove_row_by_id('Venda_list', '{$detail_id}')");
  247.     }
  248.     
  249.     /**
  250.      * Load the items list from session
  251.      * @param $param URL parameters
  252.      */
  253.     public function onReload($param)
  254.     {
  255.         // read session items
  256.         $items TSession::getValue(__CLASS__.'_items');
  257.         
  258.         $this->detail_list->clear(); // clear detail list
  259.         
  260.         if ($items)
  261.         {
  262.             foreach ($items as $list_item)
  263.             {
  264.                 $item = (object) $list_item;
  265.                 
  266.                 $row $this->detail_list->addItem$item );
  267.                 $row->id $list_item['itv_cod'];
  268.             }
  269.         }
  270.         
  271.         $this->loaded TRUE;
  272.     }
  273.     
  274.     /**
  275.      * Load Master/Detail data from database to form/session
  276.      */
  277.     public function onEdit($param)
  278.     {
  279.         try
  280.         {
  281.             TTransaction::open('bd_venda');
  282.             
  283.             if (isset($param['key']))
  284.             {
  285.                 $key $param['key'];
  286.                 
  287.                 $object = new Venda($key);
  288.                 $items  Itensvenda::where('cod_venda''='$key)->load();
  289.                 
  290.                 $session_items = array();
  291.                 foreach( $items as $item )
  292.                 {
  293.                     $item_key $item->itv_cod;
  294.                     $session_items[$item_key] = $item->toArray();
  295.                     $session_items[$item_key]['itv_cod'] = $item->itv_cod;
  296.                     $session_items[$item_key]['cod_prod'] = $item->cod_prod;
  297.                     $session_items[$item_key]['preco_venda'] = $item->preco_venda;
  298.                     $session_items[$item_key]['quantidade'] = $item->quantidade;
  299.                    // $session_items[$item_key]['desconto'] = $item->desconto;
  300.                 }
  301.                 TSession::setValue(__CLASS__.'_items'$session_items);
  302.                 
  303.                 $this->form->setData($object); // fill the form with the active record data
  304.                 $this->onReload$param ); // reload items list
  305.                 TTransaction::close(); // close transaction
  306.             }
  307.             else
  308.             {
  309.                 $this->form->clear(TRUE);
  310.                 TSession::setValue(__CLASS__.'_items'null);
  311.                 $this->onReload$param );
  312.             }
  313.         }
  314.         catch (Exception $e// in case of exception
  315.         {
  316.             new TMessage('error'$e->getMessage());
  317.             TTransaction::rollback();
  318.         }
  319.     }
  320.     
  321.     /**
  322.      * Save the Master/Detail data from form/session to database
  323.      */
  324.     public function onSave()
  325.     {
  326.     
  327.         try
  328.         {
  329.             // open a transaction with database
  330.             TTransaction::open('bd_venda');
  331.             
  332.             $data $this->form->getData();
  333.             $master = new Venda
  334.             $master->fromArray( (array) $data);
  335.             $this->form->validate(); // Valida a data do formulario
  336.             
  337.             $master->store(); // save master object
  338.             // delete details
  339.             $old_items Itensvenda::where('cod_venda''='$master->ven_cod)->load();
  340.             
  341.             $keep_items = array();
  342.             
  343.             // get session items
  344.             $items TSession::getValue(__CLASS__.'_items');
  345.             
  346.             if( $items )
  347.             {
  348.                 foreach( $items as $item )
  349.                 {
  350.                     if (substr($item['itv_cod'],0,1) == 'X' // new record
  351.                     {
  352.                         $detail = new Itensvenda;
  353.                     }
  354.                     else
  355.                     {
  356.                         $detail Itensvenda::find($item['itv_cod']);
  357.                     }
  358.                     $detail->cod_prod  $item['cod_prod'];
  359.                     $detail->preco_venda  $item['preco_venda'];
  360.                     $detail->quantidade  $item['quantidade'];
  361.                     $detail->cod_venda $master->ven_cod;
  362.                     
  363.                     // Criamos um Campo  ven_total  para guardar o total da venda
  364.                      $detail->ven_total = ($detail->quantidade * ($detail->preco_venda));
  365.                    
  366.                     $detail->store(); // Guarda os itens dos detalhes
  367.       
  368.                     $this->form->setData($data); //  Preencha a Data no Formulário
  369.                 
  370.                     $master->ven_total += $detail->ven_total;
  371.                      
  372.                     $master->venda_data date('Y-m-d H:m:s');
  373.                     
  374.                     $keep_items[] = $detail->itv_cod;
  375.                 }
  376.                       $master->store();
  377.             }
  378.             
  379.             if ($old_items)
  380.             {
  381.                 foreach ($old_items as $old_item)
  382.                 {
  383.                     if (!in_array$old_item->itv_cod$keep_items))
  384.                     {
  385.                         $old_item->delete();
  386.                     }
  387.                 }
  388.             }
  389.             
  390.              
  391.             TTransaction::close(); // close the transaction
  392.             
  393.             // reload form and session items
  394.             $this->onEdit(array('key'=>$master->ven_cod));
  395.             
  396.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  397.         }
  398.         catch (Exception $e// in case of exception
  399.         {
  400.             new TMessage('error'$e->getMessage());
  401.             $this->form->setData$this->form->getData() ); // keep form data
  402.             TTransaction::rollback();
  403.         }
  404.         $this->form->clear(TRUE);  //Para Limpar os campos do formulario Mestre
  405.     }
  406.     
  407.     
  408.     
  409.     /**
  410.      * Show the page
  411.      */
  412.     public function show()
  413.     {
  414.         // check if the datagrid is already loaded
  415.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  416.         {
  417.             $this->onReloadfunc_get_arg(0) );
  418.         }
  419.         parent::show();
  420.     }
  421. }
  422. Pelo que espero deferimento  </your>
MS

Boa tarde Nataniel,
Primeiramente quero agradecer pela ajudar. Porem ainda estou com dificuldade de fazer o campo buscar funcionar:

No campo busca estou buscando meu nome como se fosse o cliente:

Ocorre o seguinte erro:

Classe ^1 não encontrada em AdiantiWidgetFormTForm::getData

File: libadiantiwrapperBootstrapFormBuilder.php : 252
AdiantiWidgetFormTForm->getData()
File: appcontrolprogramChangeGrid.class.php : 154
AdiantiWrapperBootstrapFormBuilder->getData()
File: :
ChangeGrid->onSearch(ChangeGrid,onSearch,MISAEl)
File: libadianticontrolTPage.php : 51
call_user_func(ChangeGrid,onSearch,ChangeGrid,onSearch,MISAEl)
File: libadianticontrolTPage.php : 205
AdiantiControlTPage->run()
File: appcontrolprogramChangeGrid.class.php : 196
AdiantiControlTPage->show()
File: libadianticoreAdiantiCoreApplication.php : 64
ChangeGrid->show(ChangeGrid,onSearch,MISAEl)
File: engine.php : 23
AdiantiCoreAdiantiCoreApplication::run(1)
File: engine.php : 65
TApplication::run(1)


O codigo:

  1. <?php
  2. class ChangeGrid extends TPage
  3. {
  4.     private $form;
  5.     private $datagrid;
  6.     private $pageNavigation;
  7.     private    $loaded;
  8.            
  9.     public function __construct()
  10.     {
  11.         parent::__construct();
  12.           
  13.         
  14.         // creates the form
  15.         $this->form = new BootstrapFormBuilder('form_search_City');
  16.         $this->form->setFormTitle('Standard DataGrid');
  17.         
  18.         $buscar = new TEntry('buscar');
  19.         $this->form->addFields( [new TLabel('Buscar:')], [$buscar] );
  20.         
  21.         // add form actions
  22.         $this->form->addAction('Find', new TAction([$this'onSearch']), 'fa:search blue');
  23.         $this->form->addActionLink('New',  new TAction(['ChangeForm','onClear']), 'fa:plus-circle green');
  24.         $this->form->addActionLink('Clear',  new TAction([$this'clear']), 'fa:eraser red');
  25.         
  26.         // keep the form filled with the search data
  27.         $this->form->setDataTSession::getValue('onSearch'));
  28.                      
  29.         // creates one datagrid
  30.         $this->datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
  31.         //$this->datagrid->style = 'min-width: 1600px';              
  32.         $this->datagrid->width "100%";
  33.        
  34.         $col_cliente    = new TDataGridColumn('cliente''Cliente''center''10%');
  35.         $col_change = new TDataGridColumn('change_id''Change''left','10%');
  36.         $col_task = new TDataGridColumn('task_id''Task''left','10%');
  37.         $col_hostaname = new TDataGridColumn('hostnames''Hostname''left','10%');
  38.         $col_data_inicial = new TDataGridColumn'data_change_inicial''Data Inicial''left','10%');
  39.         $col_data_final = new TDataGridColumn('data_change_final''Data Final''left','10%');
  40.         $col_atividade = new TDataGridColumn('atividade''Atividade''left','10%');
  41.         $col_st_atividade = new TDataGridColumn('status_atividade''Status de Atividade''left','10%');
  42.         $col_st_change = new TDataGridColumn('status_change''Status da Change''left','10%');
  43.         $col_coord = new TDataGridColumn('coordinator''Coordinator''left','10%');
  44.        
  45.         // add the columns
  46.         
  47.         $this->datagrid->addColumn($col_cliente);
  48.         $this->datagrid->addColumn($col_change);
  49.         $this->datagrid->addColumn($col_task);
  50.         $this->datagrid->addColumn($col_hostaname);
  51.         $this->datagrid->addColumn($col_data_inicial);
  52.         $this->datagrid->addColumn($col_data_final);
  53.         $this->datagrid->addColumn($col_atividade);
  54.         $this->datagrid->addColumn($col_st_atividade);
  55.         $this->datagrid->addColumn($col_st_change);
  56.         $this->datagrid->addColumn($col_coord);
  57.         
  58.         $col_cliente->setAction( new TAction([$this'onReload']),   ['order' => 'cliente']);
  59.         $col_do_im->setAction( new TAction([$this'onReload']), ['order' => 'id_do_im']);
  60.               
  61.         $edit = new TDataGridAction(array ('ChangeForm''onEdit'));
  62.         $this->datagrid->addQuickAction('Editar'$edit'id''ico_edit.png'); 
  63.                         
  64.         // creates the datagrid model
  65.         $this->datagrid->createModel();            
  66.               
  67.         $this->pageNavigation = new TPageNavigation;
  68.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));  
  69.         $this->pageNavigation->setWidth($this->datagrid->getWidth());         
  70.       
  71.                 
  72.         // wrap the page content using vertical box
  73.         $vbox = new TVBox;
  74.         $vbox->style 'width: 100%';
  75.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  76.         //$vbox->add($panel);
  77.         $vbox->add($this->form);
  78.         $vbox->add(TPanelGroup::pack(''$this->datagrid$this->pageNavigation)); // add a row for page navigation
  79.         
  80.         TTransaction::close(); // close transaction
  81.         parent::add($vbox);
  82.     }
  83.        
  84.     /**
  85.      * Load the data into the datagrid
  86.      */
  87.     
  88.     public function onReload($param NULL)
  89.     {
  90.     try
  91.         {
  92.             TTransaction::open('sample');
  93.             
  94.             $repository = new TRepository('SystemChange');
  95.             $limit 10;
  96.             
  97.             $criteria = new TCriteria;
  98.             
  99.             if (empty($param['order']))
  100.             {
  101.                 $param['order'] = 'id';
  102.                 $param['direction'] = 'asc';
  103.             }
  104.             
  105.             $criteria->setProperties($param); // order, offset
  106.             $criteria->setProperty('limit'$limit);
  107.             
  108.             if (TSession::getValue('Find_filter'))
  109.             {
  110.                 // add the filter stored in the session to the criteria
  111.                 $criteria->add(TSession::getValue('Find_filter'));
  112.             }
  113.             
  114.             $objects $repository->load$criteria );
  115.                         
  116.             
  117.             $this->datagrid->clear();
  118.             
  119.             if ($objects)
  120.             {
  121.                 foreach($objects as $object)
  122.                 {
  123.                     $this->datagrid->addItem($object);
  124.                 }
  125.             }
  126.             
  127.             $criteria->resetProperties();
  128.             $count $repository->count($criteria);
  129.             
  130.             $this->pageNavigation->setCount($count); // count of records
  131.             $this->pageNavigation->setProperties($param); // order, page
  132.             $this->pageNavigation->setLimit($limit); // limit
  133.                         
  134.             TTransaction::close();
  135.             $this->loaded true;
  136.         }
  137.         catch (Exception $e)
  138.         {
  139.             new TMessage('error'$e->getMessage());
  140.             TTransaction::rollback(); // undo all pending operations    
  141.         }
  142.         
  143.         $this->loaded TRUE;
  144.     }
  145.    
  146.     public function show()
  147.     {
  148.        if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  149.        {
  150.            $this->onReloadfunc_get_arg(0) );
  151.        }
  152.        parent::show();
  153.     }
  154.     public function onSearch() 
  155.     {
  156.     
  157.         // get the search form data
  158.         $data $this->form->getData($data);
  159.         
  160.         // check if the user has filled the form
  161.         if (isset($data->buscar))
  162.         {            
  163.             $filter1 = new TFilter('buscar''like'"%{$data->buscar}%");
  164.             $filter2 = new TFilter('campo2''like'"%{$data->buscar}%");
  165.             $filter3 = new TFilter('campo3''like'"%{$data->buscar}%");
  166.             $crit = new TCriteria();
  167.             $crit->add($filter1,TExpression::OR_OPERATOR);
  168.             $crit->add($filter2,TExpression::OR_OPERATOR);
  169.             $crit->add($filter2,TExpression::OR_OPERATOR);
  170.             
  171.             TSession::setValue('Find_filter'$crit);            
  172.                         
  173.             // fill the form with data again
  174.             $this->form->setData($data);
  175.         }
  176.         
  177.         $param = array();
  178.         $param['offset']    =0;
  179.         $param['first_page']=1;
  180.         $this->onReload($param);
  181.         
  182.         
  183.     }    
  184. }
  185. </code>


NR

Altere o seguinte:
  1. <?php
  2. // onSearch
  3. //$data = $this->form->getData($data);
  4. $data $this->form->getData();
  5. ?>