Lançado Adianti Framework 7.6!
Clique aqui para saber mais
DataGrid com valor numerico Bom dia... Estou com dificuldade em apresentar os campos Maior valor e Menor valor na grid do formulário, como fazer isso? Segue anexo o código do formulário e desenho da tela. ...
RF
DataGrid com valor numerico  
Bom dia...

Estou com dificuldade em apresentar os campos Maior valor e Menor valor na grid do formulário, como fazer isso? Segue anexo o código do formulário e desenho da tela.

  1. <?php
  2. /**
  3.  * ListaCadatroProdutos Form List
  4.  * @author  <your name here>
  5.  */
  6. class ListaCadatroProdutos extends TPage
  7. {
  8.     protected $form// form
  9.     protected $datagrid// datagrid
  10.     protected $pageNavigation;
  11.     protected $loaded;
  12.     
  13.     /**
  14.      * Form constructor
  15.      * @param $param Request
  16.      */
  17.     public function __construct$param )
  18.     {
  19.         parent::__construct();
  20.         
  21.         // creates the form
  22.         $this->form = new TQuickForm('form_Produto');
  23.         $this->form->class 'tform'// change CSS class
  24.         
  25.         $this->form->style 'display: table;width:100%'// change style
  26.         $this->form->setFormTitle('Produto');
  27.         
  28.         // create the form fields
  29.         $id              = new TEntry('id');
  30.         $tipo            = new TCombo('tipo');
  31.         $bairro          = new TEntry('bairro');
  32.         $unidis          = new TEntry('unidis');
  33.         $vlmaior         = new TEntry('vlmaior');
  34.         $vlmenor         = new TEntry('vlmenor');
  35.         $empreendimento  = new TEntry('empreendimento');
  36.         // definição dos formatos dos campos
  37.         $vlmaior        -> setNumericMask(2,',''.'true);
  38.         $vlmenor        -> setNumericMask(2,',''.'true);
  39.         $empreendimento ->style "text-transform: uppercase";
  40.         $bairro         ->style "text-transform: uppercase";
  41.         $unidis         ->style "text-transform: uppercase"
  42.         $id             ->setEditable(FALSE);
  43.         //Itens do estagio
  44.         $itemEstagio= array();
  45.         $itemEstagio['NA PLANTA']             = 'NA PLANTA'
  46.         $itemEstagio['PRONTO PARA MORAR']     = 'PRONTO PARA MORAR';
  47.         $tipo->setValue('PRONTO PARA MORAR');
  48.         $tipo->addItems($itemEstagio);
  49.         // add the fields
  50.         $this->form->addQuickField('Código'$id,  200 );
  51.         $this->form->addQuickField('Tipo'$tipo,  200 );
  52.         $this->form->addQuickField('Bairro'$bairro,  200 );
  53.         $this->form->addQuickField('Unidade disponível'$unidis,  450 );
  54.         $this->form->addQuickField('Maior valor'$vlmaior,  200 );
  55.         $this->form->addQuickField('Menor valor'$vlmenor,  200 );
  56.         $this->form->addQuickField('Produto'$empreendimento,  200 );
  57.         /** samples
  58.          $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  59.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  60.          $fieldX->setSize( 100, 40 ); // set size
  61.          **/
  62.          
  63.         // create the form actions
  64.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  65.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onClear')), 'bs:plus-sign green');
  66.         
  67.         // creates a Datagrid
  68.         $this->datagrid = new TDataGrid;
  69.         ##LIST_DECORATOR##
  70.         $this->datagrid->style 'width: 100%';
  71.         $this->datagrid->setHeight(320);
  72.         // $this->datagrid->datatable = 'true';
  73.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  74.  
  75.         // creates the datagrid columns
  76.         $column_id             = new TDataGridColumn('id''Código''left');
  77.         $column_tipo           = new TDataGridColumn('tipo''Tipo''left');
  78.         $column_bairro         = new TDataGridColumn('bairro''Bairro''left');
  79.         $column_unidis         = new TDataGridColumn('unidis''Unidade disponível''left');
  80.         $column_vlmaior        = new TDataGridColumn('vlmaior''Maior valor''left');
  81.         $column_vlmenor        = new TDataGridColumn('vlmenor''Menor valor''left');
  82.         $column_empreendimento = new TDataGridColumn('empreendimento''Produto''left');
  83.      
  84.         // add the columns to the DataGrid
  85.         $this->datagrid->addColumn($column_id);
  86.         $this->datagrid->addColumn($column_tipo);
  87.         $this->datagrid->addColumn($column_bairro);
  88.         $this->datagrid->addColumn($column_unidis);
  89.         $this->datagrid->addColumn($column_vlmaior);
  90.         $this->datagrid->addColumn($column_vlmenor);
  91.         $this->datagrid->addColumn($column_empreendimento);
  92.         // creates two datagrid actions
  93.         $action1 = new TDataGridAction(array($this'onEdit'));
  94.         $action1->setUseButton(TRUE);
  95.         $action1->setButtonClass('btn btn-default');
  96.         //$action1->setLabel(_t('Edit'));
  97.         $action1->setImage('fa:pencil-square-o blue fa-lg');
  98.         $action1->setField('id');
  99.         
  100.         /*
  101.         $action2 = new TDataGridAction(array($this, 'onDelete'));
  102.         $action2->setUseButton(TRUE);
  103.         $action2->setButtonClass('btn btn-default');
  104.         $action2->setLabel(_t('Delete'));
  105.         $action2->setImage('fa:trash-o red fa-lg');
  106.         $action2->setField('id');
  107.         */
  108.         // add the actions to the datagrid
  109.         $this->datagrid->addAction($action1);
  110.        // $this->datagrid->addAction($action2);
  111.         
  112.         // create the datagrid model
  113.         $this->datagrid->createModel();
  114.         
  115.         // creates the page navigation
  116.         $this->pageNavigation = new TPageNavigation;
  117.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  118.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  119.         
  120.         /* vertical box container
  121.         $container = new TVBox;
  122.         $container->style = 'width: 90%';
  123.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  124.         $container->add($this->form);
  125.         $container->add($this->datagrid);
  126.         $container->add($this->pageNavigation);
  127.         
  128.         parent::add($container);
  129.         */
  130.         
  131.         
  132.         // Sub Menu Bonito
  133.         $container = new TVBox;
  134.         $container->style 'width: 90%';
  135.         $container->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  136.         $container->add($this->form);
  137.         $container->add(TPanelGroup::pack(''$this->datagrid));
  138.         $container->add($this->pageNavigation);
  139.         
  140.         parent::add($container);
  141.     }
  142.     
  143.     
  144.     /**
  145.      * Load the datagrid with data
  146.      */
  147.     public function onReload($param NULL)
  148.     {
  149.         try
  150.         {
  151.             // open a transaction with database 'sample'
  152.             TTransaction::open('sample');
  153.             
  154.             // creates a repository for Produto
  155.             $repository = new TRepository('Produto');
  156.             $limit 10;
  157.             // creates a criteria
  158.             $criteria = new TCriteria;
  159.             
  160.             // default order
  161.             if (empty($param['order']))
  162.             {
  163.                 $param['order'] = 'id';
  164.                 $param['direction'] = 'asc';
  165.             }
  166.             $criteria->setProperties($param); // order, offset
  167.             $criteria->setProperty('limit'$limit);
  168.             
  169.             if (TSession::getValue('Produto_filter'))
  170.             {
  171.                 // add the filter stored in the session to the criteria
  172.                 $criteria->add(TSession::getValue('Produto_filter'));
  173.             }
  174.             
  175.             // load the objects according to criteria
  176.             $objects $repository->load($criteriaFALSE);
  177.             
  178.             $this->datagrid->clear();
  179.             if ($objects)
  180.             {
  181.                 // iterate the collection of active records
  182.                 foreach ($objects as $object)
  183.                 {
  184.                     // add the object inside the datagrid
  185.                     $this->datagrid->addItem($object);
  186.                 }
  187.             }
  188.             
  189.             // reset the criteria for record count
  190.             $criteria->resetProperties();
  191.             $count$repository->count($criteria);
  192.             
  193.             $this->pageNavigation->setCount($count); // count of records
  194.             $this->pageNavigation->setProperties($param); // order, page
  195.             $this->pageNavigation->setLimit($limit); // limit
  196.             
  197.             // close the transaction
  198.             TTransaction::close();
  199.             $this->loaded true;
  200.         }
  201.         catch (Exception $e// in case of exception
  202.         {
  203.             // shows the exception error message
  204.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  205.             
  206.             // undo all pending operations
  207.             TTransaction::rollback();
  208.         }
  209.     }
  210.     
  211.     /**
  212.      * Ask before deletion
  213.      */
  214.     public function onDelete($param)
  215.     {
  216.         // define the delete action
  217.         $action = new TAction(array($this'Delete'));
  218.         $action->setParameters($param); // pass the key parameter ahead
  219.         
  220.         // shows a dialog to the user
  221.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  222.     }
  223.     
  224.     /**
  225.      * Delete a record
  226.      */
  227.     public function Delete($param)
  228.     {
  229.         try
  230.         {
  231.             $key=$param['key']; // get the parameter $key
  232.             TTransaction::open('sample'); // open a transaction with database
  233.             $object = new Produto($keyFALSE); // instantiates the Active Record
  234.             $object->delete(); // deletes the object from the database
  235.             TTransaction::close(); // close the transaction
  236.             $this->onReload$param ); // reload the listing
  237.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  238.         }
  239.         catch (Exception $e// in case of exception
  240.         {
  241.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  242.             TTransaction::rollback(); // undo all pending operations
  243.         }
  244.     }
  245.     
  246.     /**
  247.      * Save form data
  248.      * @param $param Request
  249.      */
  250.     public function onSave$param )
  251.     {
  252.         try
  253.         {
  254.             TTransaction::open('sample'); // open a transaction
  255.             
  256.             /**
  257.             // Enable Debug logger for SQL operations inside the transaction
  258.             TTransaction::setLogger(new TLoggerSTD); // standard output
  259.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  260.             **/
  261.             
  262.             $this->form->validate(); // validate form data
  263.             
  264.             $object = new Produto;  // create an empty object
  265.             $data $this->form->getData(); // get form data as array
  266.             $data  ->bairro strtoupper($data->bairro);
  267.             $data  ->empreendimento strtoupper($data->empreendimento);
  268.             $data  ->unidis strtoupper($data->unidis);
  269.             $object->fromArray( (array) $data); // load the object with data
  270.             $object->store(); // save the object
  271.             
  272.             // get the generated id
  273.             $data->id $object->id;
  274.             
  275.             $this->form->setData($data); // fill form data
  276.             TTransaction::close(); // close the transaction
  277.             
  278.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved')); // success message
  279.             $this->onReload(); // reload the listing
  280.         }
  281.         catch (Exception $e// in case of exception
  282.         {
  283.             new TMessage('error'$e->getMessage()); // shows the exception error message
  284.             $this->form->setData$this->form->getData() ); // keep form data
  285.             TTransaction::rollback(); // undo all pending operations
  286.         }
  287.     }
  288.     
  289.     /**
  290.      * Clear form data
  291.      * @param $param Request
  292.      */
  293.     public function onClear$param )
  294.     {
  295.         $this->form->clear(TRUE);
  296.     }
  297.     
  298.     /**
  299.      * Load object to form data
  300.      * @param $param Request
  301.      */
  302.     public function onEdit$param )
  303.     {
  304.         try
  305.         {
  306.             if (isset($param['key']))
  307.             {
  308.                 $key $param['key'];  // get the parameter $key
  309.                 TTransaction::open('sample'); // open a transaction
  310.                 $object = new Produto($key); // instantiates the Active Record
  311.                 $this->form->setData($object); // fill the form
  312.                 TTransaction::close(); // close the transaction
  313.             }
  314.             else
  315.             {
  316.                 $this->form->clear(TRUE);
  317.             }
  318.         }
  319.         catch (Exception $e// in case of exception
  320.         {
  321.             new TMessage('error'$e->getMessage()); // shows the exception error message
  322.             TTransaction::rollback(); // undo all pending operations
  323.         }
  324.     }
  325.     
  326.     /**
  327.      * method show()
  328.      * Shows the page
  329.      */
  330.     public function show()
  331.     {
  332.         // check if the datagrid is already loaded
  333.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  334.         {
  335.             $this->onReloadfunc_get_arg(0) );
  336.         }
  337.         parent::show();
  338.     }
  339. }

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 (5)


PF

Olá colega.
Dê uma olhada em www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra
Neste link aí tem um exemplo...

Também, procurando no forum por setTransformer tem mais exemplos.

T+
PF

Em Tempo, :www.adianti.com.br/framework_files/tutor/index.php?class=DatagridTra
PF

a classe é DatagridTransformView
RF

Boa tarde...

Obrigado pela ajuda, mas nenhum dos links indicados funciona. Vou pesquisar em respostas anteriores, talvez alguem já tenha a resposta certa.
PF

Procure no tutor, em Datagrid, Datagrid transformers... Copiei e colei o endereço, mas não sei porque cargas dagua, o link não vai completo... Espero ter ajudado. T+