Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Mostrar nome do campo relacionado no Datagrid Bom dia! Tabela de Cidades esta relacionada com tabela de Paises. Mas no datagrid traz o ID do pais na tabela Cidade como padrao. Preciso mostrar o nome do pais tambem. Table Country Id DS_country Tabel City Id Ds_city Country_id Em anexo os fontes. Obrigado ...
MM
Mostrar nome do campo relacionado no Datagrid  
Bom dia!
Tabela de Cidades esta relacionada com tabela de Paises. Mas no datagrid traz o ID do pais na tabela Cidade como padrao.
Preciso mostrar o nome do pais tambem.
Table Country
Id
DS_country
Tabel City
Id
Ds_city
Country_id
Em anexo os fontes.
Obrigado

  1. <?php
  2. /**
  3.  * TradeCity Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class Cidade extends TRecord
  7. {
  8.     const TABLENAME 'public.trade_city';
  9.     const PRIMARYKEY'id';
  10.     const IDPOLICY =  'serial'// {max, serial}
  11.     
  12.     
  13.     private $pais;
  14.     /**
  15.      * Constructor method
  16.      */
  17.     public function __construct($id NULL$callObjectLoad TRUE)
  18.     {
  19.         parent::__construct($id$callObjectLoad);
  20.         parent::addAttribute('ds_city');
  21.         parent::addAttribute('county_id');
  22.         parent::addAttribute('ds_country');    
  23.      }
  24.     
  25.     /**
  26.      * Method set_pais
  27.      * Sample of usage: $trade_city->pais = $object;
  28.      * @param $object Instance of Pais
  29.      */
  30.     public function set_pais(Pais $object)
  31.     {
  32.         $this->pais $object;
  33.         $this->country_id $object->id;
  34.     }
  35.     
  36.     /**
  37.      * Method get_pais
  38.      * Sample of usage: $trade_city->pais->attribute;
  39.      * @returns Pais instance
  40.      */
  41.     public function get_pais()
  42.     {
  43.         // loads the associated object
  44.         if (empty($this->pais))
  45.             $this->pais = new Pais($this->country_id);
  46.     
  47.         // returns the associated object
  48.         return $this->pais;
  49.     }
  50.     
  51. }
  1. <?php
  2. /**
  3.  * CidadeForm Registration
  4.  * @author  <your name here>
  5.  */
  6. class CidadeForm extends TPage
  7. {
  8.     protected $form// form
  9.     
  10.     use Adianti\Base\AdiantiStandardFormTrait// Standard form methods
  11.     
  12.     /**
  13.      * Class constructor
  14.      * Creates the page and the registration form
  15.      */
  16.     function __construct()
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->setDatabase('Teste');              // defines the database
  21.         $this->setActiveRecord('Cidade');     // defines the active record
  22.         
  23.         // creates the form
  24.         $this->form = new TQuickForm('form_Cidade');
  25.         $this->form->class 'tform'// change CSS class
  26.         
  27.         $this->form->style 'display: table;width:100%'// change style
  28.         
  29.         // define the form title
  30.         $this->form->setFormTitle('Cidade');
  31.         
  32.         // create the form fields
  33.         $id = new TEntry('id');
  34.         $ds_city = new TEntry('ds_city');
  35.         $county_id = new TEntry('county_id');
  36.         // add the fields
  37.         $this->form->addQuickField('Id'$id,  100 );
  38.         $this->form->addQuickField('Ds City'$ds_city,  200 );
  39.         $this->form->addQuickField('Country Id'$county_id,  100 );
  40.         
  41.         if (!empty($id))
  42.         {
  43.             $id->setEditable(FALSE);
  44.         }
  45.         
  46.         /** samples
  47.          $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
  48.          $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  49.          $fieldX->setSize( 100, 40 ); // set size
  50.          **/
  51.          
  52.         // create the form actions
  53.         $this->form->addQuickAction(_t('Save'), new TAction(array($this'onSave')), 'fa:floppy-o');
  54.         $this->form->addQuickAction(_t('New'),  new TAction(array($this'onEdit')), 'bs:plus-sign green');
  55.         
  56.         // vertical box container
  57.         $container = new TVBox;
  58.         $container->style 'width: 90%';
  59.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  60.         $container->add($this->form);
  61.         
  62.         parent::add($container);
  63.     }
  64. }
  1. <?php
  2. /**
  3.  * CidadeList Listing
  4.  * @author  <your name here>
  5.  */
  6. class CidadeList extends TStandardList
  7. {
  8.     protected $form;     // registration form
  9.     protected $datagrid// listing
  10.     protected $pageNavigation;
  11.     protected $formgrid;
  12.     protected $deleteButton;
  13.     protected $transformCallback;
  14.     
  15.     /**
  16.      * Page constructor
  17.      */
  18.     public function __construct()
  19.     {
  20.         parent::__construct();
  21.         
  22.         parent::setDatabase('Teste');            // defines the database
  23.         parent::setActiveRecord('Cidade');   // defines the active record
  24.         parent::setDefaultOrder('id''asc');         // defines the default order
  25.         // parent::setCriteria($criteria) // define a standard filter
  26.         parent::addFilterField('id''like''Cod'); // filterField, operator, formField
  27.         parent::addFilterField('ds_city''like''Nome'); // filterField, operator, formField
  28.         parent::addFilterField('county_id''like''Cod Pais'); // filterField, operator, formField
  29.         parent::addFilterField('ds_country''like''Nome'); // filterField, operator, formField
  30.         
  31.         // creates the form
  32.         $this->form = new TQuickForm('form_search_Cidade');
  33.         $this->form->class 'tform'// change CSS class
  34.         
  35.         $this->form->style 'display: table;width:100%'// change style
  36.         $this->form->setFormTitle('Cidade');
  37.         
  38.         // create the form fields
  39.         $id = new TEntry('id');
  40.         $ds_city = new TEntry('ds_city');
  41.         $county_id = new TEntry('county_id');
  42.         $ds_country = new TLabel('ds_country');
  43.         // add the fields
  44.         $this->form->addQuickField('Id'$id,  200 );
  45.         $this->form->addQuickField('Ds City'$ds_city,  200 );
  46.         $this->form->addQuickField('County Id'$county_id,  200 );
  47.         $this->form->addQuickField('Nome Pais'$ds_country,  200 );
  48.         
  49.         // keep the form filled during navigation with session data
  50.         $this->form->setDataTSession::getValue('Cidade_filter_data') );
  51.         
  52.         // add the search form actions
  53.         $this->form->addQuickAction(_t('Find'), new TAction(array($this'onSearch')), 'fa:search');
  54.         $this->form->addQuickAction(_t('New'),  new TAction(array('CidadeForm''onEdit')), 'bs:plus-sign green');
  55.         
  56.         // creates a DataGrid
  57.         $this->datagrid = new TDataGrid;
  58.         
  59.         $this->datagrid->style 'width: 100%';
  60.         $this->datagrid->datatable 'true';
  61.         // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
  62.         
  63.         // creates the datagrid columns
  64.         $column_id = new TDataGridColumn('id''Cod''left');
  65.         $column_ds_city = new TDataGridColumn('ds_city''Nome''left');
  66.         $column_county_id = new TDataGridColumn('county_id''Cod''left');
  67.         $column_ds_country = new TDataGridColumn('ds_country''Nome Pais''left');
  68.         // add the columns to the DataGrid
  69.         $this->datagrid->addColumn($column_id);
  70.         $this->datagrid->addColumn($column_ds_city);
  71.         $this->datagrid->addColumn($column_county_id);
  72.         $this->datagrid->addColumn($column_ds_country);
  73.         // creates the datagrid column actions
  74.         $order_ds_country = new TAction(array($this'onReload'));
  75.         $order_ds_country->setParameter('order''ds_country');
  76.         $column_ds_country->setAction($order_ds_country);
  77.         
  78.         
  79.         // create EDIT action
  80.         $action_edit = new TDataGridAction(array('CidadeForm''onEdit'));
  81.         $action_edit->setUseButton(TRUE);
  82.         $action_edit->setButtonClass('btn btn-default');
  83.         $action_edit->setLabel(_t('Edit'));
  84.         $action_edit->setImage('fa:pencil-square-o blue fa-lg');
  85.         $action_edit->setField('id');
  86.         $this->datagrid->addAction($action_edit);
  87.         
  88.         // create DELETE action
  89.         $action_del = new TDataGridAction(array($this'onDelete'));
  90.         $action_del->setUseButton(TRUE);
  91.         $action_del->setButtonClass('btn btn-default');
  92.         $action_del->setLabel(_t('Delete'));
  93.         $action_del->setImage('fa:trash-o red fa-lg');
  94.         $action_del->setField('id');
  95.         $this->datagrid->addAction($action_del);
  96.         
  97.         // create the datagrid model
  98.         $this->datagrid->createModel();
  99.         
  100.         // create the page navigation
  101.         $this->pageNavigation = new TPageNavigation;
  102.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  103.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  104.         
  105.         // vertical box container
  106.         $container = new TVBox;
  107.         $container->style 'width: 90%';
  108.         // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  109.         $container->add($this->form);
  110.         $container->add($this->datagrid);
  111.         $container->add($this->pageNavigation);
  112.         
  113.         parent::add($container);
  114.     }
  115.     
  116. }

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


NR

  1. <?php
  2. $column_ds_country = new TDataGridColumn('pais->ds_country''Nome Pais''left');
  3. ?>