RB
Erro ao usar paagiinaação DataGrid
Pessoal,
Ao usar paginação dados não são carregados
segue código abaixo
Ao usar paginação dados não são carregados
segue código abaixo
- <?php
- /**
- * DataGridClienteFisico
- *
- */
- class DataGridClienteFisico extends TPage
- {
- private $datagrid, $pageNavigation, $loaded;
- public function __construct()
- {
- parent::__construct();
- // creates one datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->width = '100%';
- // add the columns
- $this->datagrid->addColumn(new TDataGridColumn('pessoa_id','#','center',''));
- $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->nome',_t('Name'),'left',''));
- $this->datagrid->addColumn(new TDataGridColumn('criacao','Data Cadastro','left',''));
- $this->datagrid->addColumn(new TDataGridColumn('telefone->numero','Telefone','left',''));
- $this->datagrid->addColumn(new TDataGridColumn('unity','Unit','left',''));
- $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->cpf','CPF','left',''));
- $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->rg','RG','left',''));
- $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->uf','UF','left',''));
- $action1 = new TDataGridAction(['FisicaForm','onEdit'],['id'=>'{pessoa_id}'] );
- $this->datagrid->addAction($action1, 'Edit','fa:search blue');
- // creates the datagrid model
- $this->datagrid->createModel();
- // search box
- $input_search = new TEntry('input_search');
- $input_search->placeholder = _t('Search');
- $input_search->setSize('100%');
- // enable fuse search by column name
- $this->datagrid->enableSearch($input_search, 'pessoa_id, pessoa->fisica->nome,pessoa->fisica->cpf');
- $panel = new TPanelGroup( _t('Datagrid search') );
- $panel->addHeaderWidget($input_search);
- $panel->add($this->datagrid)->style = 'overflow-x:auto';
- $panel->addFooter('footer');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($panel);
- parent::add($vbox);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'sgv'
- TTransaction::open('sgv');
- // creates a repository for PessoaVinculo
- $repository = new TRepository('PessoaVinculo');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'pessoa_id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count = $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Executed when the user clicks at the view button
- */
- public static function onView($param)
- {
- // get the parameter and shows the message
- $code = $param['pessoa_id'];
- $name = $param['pessoa->fisica->nome'];
- new TMessage('info', "The code is: <b>$code</b> <br> The name is : <b>$name</b>");
- }
- /**
- * method show()
- * Shows the page
- */
- function show()
- {
- // check if the datagrid is already loaded
- if (!$this->loaded)
- {
- $this->onReload( func_get_arg(0) );
- }
- parent::show();
- }
- }
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