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

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

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