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

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. ?>