Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Difuculdade em carregar grid com array Olá, Estou tentando carregar uma grid com dados retornado de um array, mas sem sucesso. Alguém pode me ajudar? Classe de teste ...
RS
Difuculdade em carregar grid com array  
Olá,
Estou tentando carregar uma grid com dados retornado de um array, mas sem sucesso.

Alguém pode me ajudar?
  1. <?php
  2.  // outros
  3. class ApplicationTranslator
  4. {
  5. //adiciopnei este método para retornar o array contendo os itens no seu rerspectivo idioma
  6.   public function getMessages()
  7.     {
  8.         return $this->messages;
  9.     }
  10. }
  11. ?>


Classe de teste
  1. <?php
  2. class CommonPage extends TPage
  3. {
  4.     private $form$datagrid$pageNavigation$loaded;
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.         // creates one datagrid
  9.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  10.         $this->datagrid->width '100%';
  11.         
  12.         // add the columns
  13.         $this->datagrid->addColumn( new TDataGridColumn('en','Inglês',    'left''') );
  14.         $this->datagrid->addColumn( new TDataGridColumn('pt','Portugês',    'left',   '') );
  15.         $this->datagrid->addColumn( new TDataGridColumn('es','Espanhol',    'left',   '') );
  16.         
  17.         // creates the datagrid model
  18.         $this->datagrid->createModel();
  19.         
  20.         $panel = new TPanelGroup_t('Table') );
  21.         //$panel->addHeaderWidget($input_search);
  22.         $panel->add($this->datagrid)->style 'overflow-x:auto';
  23.         $panel->addFooter('footer');
  24.         
  25.         // wrap the page content using vertical box
  26.         $vbox = new TVBox;
  27.         $vbox->style 'width: 100%';
  28.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  29.         $vbox->add($panel);
  30.         parent::add($vbox);
  31.     }
  32.     /**
  33.      * Load the data into the datagrid
  34.      */
  35.     function onReload($param NULL)
  36.     {
  37.         try
  38.         {
  39.             $file ApplicationTranslator::getInstance();
  40.             $languages $file->getMessages();
  41.             $limit 10;
  42.             
  43.             $this->datagrid->clear();
  44.             if ($languages)
  45.             {   
  46.                 foreach ($languages as $key => $values)
  47.                 {
  48.                     $item = new stdClass();
  49.                     $item->en $languages['en'];
  50.                     //echo $value;
  51.                     $this->datagrid->addItem($item);
  52.                     /*
  53.                      * objetivo é carregar desta forma
  54.                      * $item->en = value->en;
  55.                      * $item->pt = value->pt;
  56.                      * $item->es = value->es;
  57.                      */
  58.                 }                
  59.             }
  60.             
  61.             $this->loaded true;            
  62.             //echo '<pre>';print_r($count);echo '<pre>';            
  63.         
  64.         catch (Exception $e
  65.         {
  66.             echo $e->getFile().' : '.$e->getLine(). "#" $e->getMessage();
  67.         }
  68.     }
  69.       
  70.     function show()
  71.     {
  72.         // check if the datagrid is already loaded
  73.         if (!$this->loaded)
  74.         {
  75.             $this->onReloadfunc_get_arg(0) );
  76.         }
  77.         parent::show();
  78.     }
  79. }
  80. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (1)


NR

Tente o seguinte:
  1. <?php
  2. foreach ($languages['en'] as $key => $value)
  3. {
  4.      $item = new stdClass();
  5.      $item->en $value;
  6.      $item->pt $languages['pt'][$key];
  7.      $item->es $languages['es'][$key];
  8.                     
  9.      $this->datagrid->addItem($item);
  10. }
  11. ?>