IM
Paginação após dados recebidos do JSON
Amigos, os números da paginação não ficam disponiveis para eu ir para proxima pagina ... o que estou errado ?
- <?php
- class ContainerTableParcelasJson extends TPage
- {
- private $datagrid;
- public function __construct()
- {
- parent::__construct();
- // creates one datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TQuickGrid);
- // add the columns
- $this->datagrid->addQuickColumn('Cod', 'cod', 'center', 50);
- $this->datagrid->addQuickColumn('Nome', 'nome', 'left', 350);
- $this->datagrid->addQuickColumn('Valor', 'valor', 'left', 150);
- $this->datagrid->addQuickColumn('Vencimento', 'dt_vcto', 'left', 150);
- //$this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>');
- $action1 = new TDataGridAction(array($this, 'onView'));
- $action2 = new TDataGridAction(array($this, 'onDelete'));
- $arrayDados = array('cod', 'nome', 'valor', 'dt_vcto', 'id_loja', 'parte', 'referencia');
- // add the actions
- $this->datagrid->addQuickAction('Cadastro', $action1, $arrayDados, 'ico_find.png', 50);
- $this->datagrid->addQuickAction('Baixar', $action2, $arrayDados, 'ico_delete.png', 50);
- $action1->setUseButton(TRUE);
- $action1->setButtonClass('btn btn-default');
- $action1->setImage('fa:search blue');
- $action2->setUseButton(TRUE);
- $action2->setButtonClass('btn btn-default');
- $action2->setImage('fa:remove red');
- // creates the datagrid model
- $this->datagrid->createModel();
- // create the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- $panel = new TPanelGroup('Caixa');
- $panel->add($this->datagrid);
- $panel->addFooter('Resumo');
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($panel);
- $vbox->add($this->pageNavigation);
- parent::add($vbox);
- }
- /**
- * Load the data into the datagrid
- */
- function onReload()
- {
- $this->datagrid->clear();
- try
- {
- $location = 'http://testserver:testserver@localhost:8085/eventos/GetDadosPromiss?dataini=01/01/2018&datafim=01/08/2018';
- $valor_id = 0;
- $resultado = Uteis::LerJSON($location);
- if (!empty($resultado))
- {
- $qtd = 10;
- $atual = (isset($_GET['pg'])) ? intval($_GET['pg']) : 1;
- $pagArquivo = array_chunk($resultado, $qtd);
- $contar = count($pagArquivo);
- $resultado = $pagArquivo[$atual-1];
- foreach ($resultado as $valor ) {
- $item = new StdClass;
- $item->cod = $valor->id_cli;
- $item->nome = $valor->nomecliente;
- $item->valor = $valor->valor;
- $item->dt_vcto = $valor->dt_vcto;
- $item->id_loja = $valor->id_loja;
- $item->parte = $valor->parte;
- $item->referencia = $valor->referencia;
- $this->datagrid->addItem($item);
- }
- }
- }
- catch (Exception $e)
- {
- echo 'Error: '. $e->getMessage();
- }
- }
- /**
- * method onDelete()
- * Executed when the user clicks at the delete button
- */
- function onDelete($param)
- {
- // get the parameter and shows the message
- //var_dump($param);
- $nome=$param['nome'];
- new TMessage('error', "Deseja realmente baixar o registro do cliente: $nome");
- }
- /**
- * method onView()
- * Executed when the user clicks at the view button
- */
- function onView($param)
- {
- // get the parameter and shows the message
- $nome=$param['nome'];
- $loja=$param['id_loja'];
- //$tele=$param['fone2cli'];
- //$ende=$param['endercli'];
- //$cpf =$param['cnpjcli'];
- $ref =$param['referencia'];
- new TMessage('info', "Cliente : $nome </br >".
- "Loja : $loja </br >".
- "referencia : $ref </br >" );
- }
- /**
- * shows the page
- */
- function show()
- {
- $this->onReload();
- parent::show();
- }
- }
Ico, eu creio que nesse caso não dá pra usar a paginação , pois ela é usada em conjunto com o TCriteria que define o LIMIT na consulta sql. se o volume de dados não for muito, dá pra vc ativar o DataTable:
Se alguém tiver outra idéia melhor, por favor postar aqui.
Ivan, to quase conseguindo. ... creio uma formula ... depois posto
Faltaram algumas configurações do TPageNavigation, o que geralmente é feito na função onReload:
Exatamente esse $Param que faltava Nataniel ... agora só to terminando um bug..
Bom, fiz essas alteraçoes e funcionou perfeito ... sem ligação nenhuma com banco de dados
Show de bola Ico! Vou fazer a minha cola pra quando precisar kkk!
Ivan, como faço para recuperar os mesmos valores digitados no filtro ... na próxima paginação ?!
Vou te mostrar a imagem ... e após o clique no botão PESQUISAR, minha consulta é retornada corretamente, mas as datas que havia digitado ...eles somem !!! queria que elas permanecessem lá no edit ... para a proxima paginação ser atualizada com o mesmo filtro.
Grato
boa noite Ico tudo certo? consegui fazer a separação, porem estou com problemas no meu pagenavigation, poderia enviar o código do onReload e os trecho do pagenavigation? Obrigado
Te mando amanhã Paulo !!!
Vou procurar, nem tava usando mais
Como prometido, segue
Paulo, acesse meu canal e veja um video que fiz ...
https://www.youtube.com/watch?v=Yj3SIc5KBek&t=254s
Aproveite e conhece o Projeto DW que temos em
www.restdw.com.br (rest)