Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro ao usar paagiinaação DataGrid Pessoal, Ao usar paginação dados não são carregados segue código abaixo ...
RB
Erro ao usar paagiinaação DataGrid  
Pessoal,
Ao usar paginação dados não são carregados

segue código abaixo
  1. <?php
  2. /**
  3.  * DataGridClienteFisico
  4.  *
  5.  */
  6. class DataGridClienteFisico extends TPage
  7. {
  8.     private $datagrid$pageNavigation$loaded;
  9.     
  10.     public function __construct()
  11.     {
  12.         parent::__construct();
  13.         
  14.         // creates one datagrid
  15.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  16.         $this->datagrid->width '100%';
  17.         
  18.         // add the columns
  19.         $this->datagrid->addColumn(new TDataGridColumn('pessoa_id','#','center',''));
  20.         $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->nome',_t('Name'),'left',''));
  21.         $this->datagrid->addColumn(new TDataGridColumn('criacao','Data Cadastro','left',''));
  22.         $this->datagrid->addColumn(new TDataGridColumn('telefone->numero','Telefone','left',''));
  23.         $this->datagrid->addColumn(new TDataGridColumn('unity','Unit','left',''));
  24.         $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->cpf','CPF','left',''));
  25.         $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->rg','RG','left',''));
  26.         $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->uf','UF','left',''));
  27.        
  28.         
  29.         $action1 = new TDataGridAction(['FisicaForm','onEdit'],['id'=>'{pessoa_id}'] );
  30.         $this->datagrid->addAction($action1'Edit','fa:search blue');
  31.         
  32.         // creates the datagrid model
  33.         $this->datagrid->createModel();
  34.         
  35.         // search box
  36.         $input_search = new TEntry('input_search');
  37.         $input_search->placeholder _t('Search');
  38.         $input_search->setSize('100%');
  39.         
  40.         // enable fuse search by column name
  41.         $this->datagrid->enableSearch($input_search'pessoa_id, pessoa->fisica->nome,pessoa->fisica->cpf');
  42.         
  43.         $panel = new TPanelGroup_t('Datagrid search') );
  44.         $panel->addHeaderWidget($input_search);
  45.         $panel->add($this->datagrid)->style 'overflow-x:auto';
  46.         $panel->addFooter('footer');
  47.         
  48.         // wrap the page content using vertical box
  49.         $vbox = new TVBox;
  50.         $vbox->style 'width: 100%';
  51.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  52.         $vbox->add($panel);
  53.         parent::add($vbox);
  54.     }
  55.     
  56.     /**
  57.      * method onReload()
  58.      * Load the datagrid with the database objects
  59.      */
  60.     function onReload($param NULL)
  61.     {
  62.         try
  63.         {
  64.             // open a transaction with database 'sgv'
  65.             TTransaction::open('sgv');
  66.             
  67.             // creates a repository for PessoaVinculo
  68.             $repository = new TRepository('PessoaVinculo');
  69.             $limit 10;
  70.             
  71.             // creates a criteria
  72.             $criteria = new TCriteria;
  73.             
  74.             // default order
  75.             if (empty($param['order']))
  76.             {
  77.                 $param['order'] = 'pessoa_id';
  78.                 $param['direction'] = 'asc';
  79.             }
  80.             
  81.             $criteria->setProperties($param); // order, offset
  82.             $criteria->setProperty('limit'$limit);            
  83.                       
  84.             // load the objects according to criteria
  85.             $objects $repository->load($criteria);
  86.             
  87.             $this->datagrid->clear();
  88.             if ($objects)
  89.             {
  90.                 // iterate the collection of active records
  91.                 foreach ($objects as $object)
  92.                 {
  93.                     // add the object inside the datagrid
  94.                     $this->datagrid->addItem($object);
  95.                 }
  96.             }
  97.             
  98.             // reset the criteria for record count
  99.             $criteria->resetProperties();
  100.             $count $repository->count($criteria);
  101.             $this->pageNavigation->setCount($count); // count of records
  102.             $this->pageNavigation->setProperties($param); // order, page
  103.             $this->pageNavigation->setLimit($limit); // limit
  104.             
  105.             // close the transaction
  106.             TTransaction::close();
  107.             $this->loaded true;
  108.         }
  109.         catch (Exception $e// in case of exception
  110.         {
  111.             new TMessage('error'$e->getMessage()); // shows the exception error message
  112.             TTransaction::rollback(); // undo all pending operations
  113.         }
  114.     }
  115.     
  116.     /**
  117.      * Executed when the user clicks at the view button
  118.      */
  119.     public static function onView($param)
  120.     {
  121.         // get the parameter and shows the message
  122.         $code $param['pessoa_id'];
  123.         $name $param['pessoa->fisica->nome'];
  124.         new TMessage('info'"The code is: <b>$code</b> <br> The name is : <b>$name</b>");
  125.     }
  126.     
  127.     /**
  128.      * method show()
  129.      * Shows the page
  130.      */
  131.     function show()
  132.     {
  133.         // check if the datagrid is already loaded
  134.         if (!$this->loaded)
  135.         {
  136.             $this->onReloadfunc_get_arg(0) );
  137.         }
  138.         parent::show();
  139.     }

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


NR

O erro diz que você está tentando chamar a função setCount numa variável que é null.
$this->pageNavigation não foi instanciada em nenhum lugar do código