Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Manter Formulários preenchido depois de TDataGridAction Ola! já estou sofrendo a um mês para solucionar uma situação, "Manter Formulário preenchido depois da ação TDataGridAction (delete ou edit)", muito básico se fosse diretamente no PHP, mas TDataGridAction essa classe ela limpa os dados da tela, tenho um TDate e dois TDBcombo, com preenchimento dependente. O foco do meu problema seria TDataGridAction que faz um post ou get na pagina executa ...
IS
Manter Formulários preenchido depois de TDataGridAction  
Ola! já estou sofrendo a um mês para solucionar uma situação, "Manter Formulário preenchido depois da ação TDataGridAction (delete ou edit)", muito básico se fosse diretamente no PHP, mas TDataGridAction essa classe ela limpa os dados da tela, tenho um TDate e dois TDBcombo, com preenchimento dependente. O foco do meu problema seria TDataGridAction que faz um post ou get na pagina executa uma ação. vou postar meu código se alguém puder me ajudar ou mesmo eu contrato o serviço para resolver este problema, estou com o framework somente a dois meses ainda não me adaptei totalmente. Já tentei variáveis de sessão, mas o tempo de execução não da certo, já tentei "form->setData($data);" mas depois que é executado TDataGridAction recarrega a classe os dados são zerados. São duas grids e 3 actions nas grids

///////////////////////////////////////////////////////////////////////

  1. <?php
  2. class  EmbarqueList extends TPage
  3. {
  4.     private $form;      // search form
  5.     private $datagrid;  // listing
  6.     private $total;
  7.     private $cartgrid;
  8.     private $pageNavigation;
  9.     private $loaded;
  10.     
  11.     /**
  12.      * Class constructor
  13.      * Creates the page, the search form and the listing
  14.      */
  15.     public function __construct()
  16.     {
  17.         parent::__construct();
  18.         new TSession;
  19.         
  20.         // creates the form
  21.         $this->form = new TForm('form_embarque');
  22.         
  23.         $panel_master = new TPanelGroup'Pesquisar' );
  24.         $vbox = new TVBox;
  25.         $vbox->style 'width: 100%';
  26.         $this->form->add($panel_master);
  27.         $panel_master->add($vbox);
  28.         
  29.         $frame_general = new TFrame;
  30.         $frame_general->class 'tframe tframe-custom';
  31.         $frame_general->style 'background:whiteSmoke';
  32.         
  33.         $table_general = new TTable;
  34.         $table_general->width '100%';
  35.         $frame_general->add($table_general);
  36.         
  37.         $frame_product = new TFrame;
  38.         $frame_product->class 'tframe tframe-custom';
  39.         
  40.         $vbox->add$frame_general );
  41.         $vbox->add$frame_product );       
  42.                
  43.         //$customer_id    = new TDBSeekButton('cidade_id', 'marca', $this->form->getName(), 'ViewViagem', 'name', 'cidade_id', 'cidade_id');
  44.         //$customer_name  = new TEntry('customer_name');
  45.         // create the form fields
  46.         $date   = new TDate('saida');
  47.         $date->setMask('dd/mm/yyyy');
  48.         $date->setDatabaseMask('yyyy-mm-dd');
  49.         $gdata TSession::getValue('recarga');
  50.        
  51.         $criteria2 = new TCriteria;  
  52.         $criteria2->add(new TFilter('(DATE(DATA_INI))''='$gdata->saida));
  53.         $cidade = new TDBCombo('cidade_id''marca''ViewViagem''cidade_id''{cidade->nome}'null$criteria2);
  54.         $cidade->enableSearch();
  55.         //$cidade->setChangeAction(new TAction(array($this, 'onChangeAction')));
  56.         
  57.         $criteria1 = new TCriteria;
  58.         $criteria1->add(new TFilter('(DATE(DATA_INI))''='$gdata->saida));
  59.         $criteria1->add(new TFilter('cidade_id''='$gdata->cidade_id));
  60.         $viagem = new TDBCombo('carro_id''marca''Viagem''id''{carro->modelo}'null$criteria1);
  61.         $viagem->enableSearch();        
  62.         //$viagem->setChangeAction(new TAction(array($this, 'onChangecarro')));
  63.         
  64.         $date->setSize(100);
  65.         $cidade->setSize(350);
  66.         $viagem->setSize(350); 
  67.         $this->form->addField($date);
  68.         //$this->form->addField($customer_id);
  69.         //$this->form->addField($customer_name);
  70.         //$this->form->addField($cidade);
  71.         $this->form->addField($cidade);
  72.         $this->form->addField($viagem);
  73.         
  74.         $table_general->addRowSet$label_date     = new TLabel('Data (*)'), $date );
  75.         $table_general->addRowSet$label_cidade = new TLabel('Cidade (*)'),  $cidade );
  76.         $table_general->addRowSet$label_viagem = new TLabel('Carro (*)'),  $viagem  );
  77.         $label_date->setFontColor('#FF0000');
  78.        
  79.         // creates a DataGrid
  80.         $this->datagrid = new TQuickGrid;
  81.         $this->cartgrid = new TQuickGrid;
  82.         // creates the datagrid columns
  83.         $this->datagrid->addQuickColumn('Paciente/Acompanhante''{paciente->NOME_PAC}''left'280);
  84.         $this->datagrid->addQuickColumn('Estabelecimento''{estabelecimento->cnes->NOME_FANTA}''left'280);
  85.        
  86.         $this->cartgrid->addQuickColumn('Paciente/Acompanhante''{paciente->NOME_PAC}''left'280);
  87.         $this->cartgrid->addQuickColumn('Estabelecimento''{estabelecimento->cnes->NOME_FANTA}''left'280);
  88.         
  89.         // creates datagrid actions
  90.         $this->datagrid->addQuickAction('Select', new TDataGridAction(array($this'onSelect')), ['id','cidade_id''viagem_id'], 'fa:check-circle-o green');
  91.         $this->cartgrid->addQuickAction('Delete', new TDataGridAction(array($this'onDelete')), 'id''fa:trash red');
  92.  
  93.         // create the datagrid model
  94.         $this->datagrid->createModel();
  95.         $this->cartgrid->createModel();
  96.         // creates the page navigation
  97.         $this->pageNavigation = new TPageNavigation;
  98.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  99.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  100.         
  101.         // creates the page structure using a table
  102.         $table2 = new TTable;
  103.         $row2=$table2->addRow();
  104.         $cell2=$row2->addCell('');
  105.         $cell2->width4
  106.         $row2->addMultiCell($this->datagrid$this->cartgrid); 
  107.         $hbox = new THBox;
  108.         $hbox->add($table2)->style.='vertical-align:top';
  109.         
  110.                 $save_button TButton::create('save', array($this'onSearch'),  _t('Save'),  'fa:save green');
  111.         $new_button  TButton::create('new',  array($this'onDelete'), _t('Clear'), 'fa:eraser red');
  112.         
  113.         // define form fields
  114.         $this->form->addField($save_button);
  115.         $this->form->addField($new_button);
  116.         
  117.         $panel_master->addFooterTHBox::pack($save_button$new_button) );
  118.         
  119.         // create the page container
  120.         $container = new TVBox;
  121.         $container->style 'width: 100%';
  122.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  123.         $container->add($this->form);
  124.         $frame_product->add($hbox);
  125.         $frame_product->add($this->pageNavigation);
  126.         parent::add($container);
  127.     }
  128.     
  129.     
  130.     /**
  131.      * Put a product inside the cart
  132.      */
  133.     public function onSelect($param)
  134.     {
  135.         // get the cart objects from session 
  136.         //$cart_objects = TSession::getValue('del_objects'); var_dump($cart_objects);
  137.         TTransaction::open('marca');
  138.         $product = new Embarque($param['key']); // load the product         
  139.         $del_objects[$product->id] = $product// add the product inside the array
  140.         //var_dump($cart_objects);
  141.         //$object->viagem_id = ''; 
  142.         //$object->store(); 
  143.         TSession::setValue('del_objects'$del_objects); // put the array back to the session
  144.         TTransaction::close();         
  145.         // reload datagrids
  146.         $this->onReloadfunc_get_arg(0) );
  147.     }
  148.      public static function onChangecarro($param)
  149.      {     
  150.             $recarga TSession::getValue('recarga');
  151.      }
  152.      public static function onChangeAction($param)
  153.      {
  154.         //$recarga = TSession::getValue('recarga');
  155.         
  156.         $criteria1 = new TCriteria;   
  157.         $criteria1->add(new TFilter('(DATE(DATA_INI))''='$recarga->saida));
  158.         $criteria1->add(new TFilter('cidade_id''='$recarga->cidade_id));
  159.         TDBCombo::reloadFromModel('form_embarque''carro_id''marca''Viagem''id''{carro->modelo}'null$criteria1false);
  160.      }  
  161.     /**
  162.      * Remove a product from the cart
  163.      */
  164.     public function onDelete($param)
  165.     {
  166.         $data $this->form->getData();
  167.         // get the cart objects from session
  168.         $del_objects TSession::getValue('del_objects');
  169.         unset($del_objects[$param['key']]); // remove the product from the array
  170.         TSession::setValue('del_objects'$del_objects); // put the array back to the session
  171.         $this->form->setData($data);
  172.         // reload datagrids
  173.         $this->onReloadfunc_get_arg(0) );
  174.     }
  175.     
  176.     /**
  177.      * method onSearch()
  178.      * Register the filter in the session when the user performs a search
  179.      */
  180.     function onSearch()
  181.     {
  182.         // get the search form data
  183.         $data $this->form->getData();
  184.         // check if the user has filled the form
  185.         if ($data->saida)
  186.         {
  187.             // creates a filter using what the user has typed
  188.             $filter = new TFilter('saida''like'"%{$data->saida}%");
  189.             // stores the filter in the session
  190.             TSession::setValue('filter1'$filter);
  191.             $object = new stdClass();
  192.             $object->saida $data->saida;
  193.             $object->cidade_id $data->cidade_id;
  194.             $object->carro_id =  $data->carro_id;
  195.             TSession::setValue('recarga',   $object);
  196.        }
  197.         else
  198.         {
  199.             TSession::setValue('filter1'NULL);
  200.             //TSession::setValue('dtsaida',   '');
  201.         }
  202.         
  203.         // fill the form with data again
  204.         $this->form->setData($data);
  205.         
  206.         $param=array();
  207.         $param['offset']    =0;
  208.         $param['first_page']=1;
  209.         $this->onReload($param);
  210.     }
  211.     
  212.     /**
  213.      * method onReload()
  214.      * Load the datagrid with the database objects
  215.      */
  216.     function onReload($param NULL)
  217.     {
  218.         try
  219.         {    
  220.             // open a transaction with database 'samples'
  221.             TTransaction::open('marca');
  222.             $recarga TSession::getValue('recarga');
  223.             // creates a repository for Product
  224.             $repository = new TRepository('Embarque');
  225.             $limit 10;
  226.             
  227.             // creates a criteria
  228.             $criteria = new TCriteria;
  229.             $criteria->setProperties($param); // order, offset
  230.             $criteria->setProperty('limit'$limit);
  231.             $criteria->setProperty('order''saida');
  232.             $criteria->add(new TFilter('cidade_id''='$recarga->cidade_id)); 
  233.             
  234.             if (TSession::getValue('filter1'))
  235.             {
  236.                 // add the filter stored in the session to the criteria
  237.                 $criteria->add(TSession::getValue('filter1'));
  238.             }
  239.             
  240.             // load the objects according to criteria
  241.             $products $repository->load($criteria);
  242.             $this->datagrid->clear();
  243.             if ($products)
  244.             {
  245.                 foreach ($products as $product)
  246.                 {
  247.                     // add the object inside the datagrid
  248.                     $this->datagrid->addItem($product);
  249.                 }
  250.             }
  251.             
  252.             $this->cartgrid->clear();
  253.             $del_objects TSession::getValue('del_objects');
  254.             if ($del_objects)
  255.             {
  256.                 foreach ($del_objects as $object)
  257.                 { 
  258.                     $this->cartgrid->addItem($object);
  259.                 }
  260.             }
  261.             
  262.             // reset the criteria for record count
  263.             $criteria->resetProperties();
  264.             $count$repository->count($criteria);
  265.             
  266.             $this->pageNavigation->setCount($count); // count of records
  267.             $this->pageNavigation->setProperties($param); // order, page
  268.             $this->pageNavigation->setLimit($limit); // limit
  269.             // close the transaction
  270.             TTransaction::close();
  271.             $this->loaded true;
  272.         }
  273.         catch (Exception $e// in case of exception
  274.         {
  275.             // shows the exception error message
  276.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  277.             // undo all pending operations
  278.             TTransaction::rollback();
  279.         }
  280.     }
  281.     
  282.     /**
  283.      * method show()
  284.      * Shows the page
  285.      */
  286.     function show()
  287.     {
  288.         // check if the datagrid is already loaded
  289.         if (!$this->loaded)
  290.         {
  291.             $this->onReloadfunc_get_arg(0) );
  292.         }
  293.         parent::show();
  294.     }
  295. }

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


MR

Tenho usado loadPage, exemplo, tenho um TDBRadio, conforme a seleção faço um loadPage carregando na grid somente o id do grupo selecionado no TDBRadio.


  1. <?php
  2.     public static function onGrupo($param)
  3.     {           
  4.     $parametros = array();
  5.     $parametros['key'] = $param['grupo'];
  6.     TApplication::loadPage('ProdutoList''onReload'$parametros);
  7.     }
  8. ?>
SF

Estou com o mesmo problema, você ja conseguiu resolver?