Disable paging and display all records when starting to search the datatable

0

I'm using servers in the datatable JQuery. PHP plus JQuery. The data is pulled from the database. I have specified that 9 records appear on each page (of pagination). But I need it when I start looking for something I want the paging to cease to exist and list 'all' records. And when you stop searching, return to normal with only 9 records per page and pagination. I know the datatable is flexible and has the API commands to change this, the problem and I do not know what it is.

Any help?

example:

 <script>

 table = $(#table).datatable({
"processing": true, 
"serverSide": true,
"order": [], 

"ajax": {
    "url": "<?php echo site_url('Locacao/ajax_list')?>",
    "type": "POST",
},
"pageLength": "9",
"bPaginate": true
})
</script>

php methodh:       

  class Locacao extends CI_Controller {

  public function __construct(){
         $parente = parent::__construct();
         $this->load->model('Locacao_model','locacao');
    }
  public function ajax_list()
  {
  $list = $this->locacao->get_datatables();
  $data = array();
  $no = $_POST['start'];

  foreach ($list as $locacao) {

    $no++;
    $row = array();

    $row[] = $locacao->id;
    $row[] = $locacao->name;
    $row[] = $locacao->date;
    $data[] = $row;
  }
  $output = array(
    "draw" => $_POST['draw'],
    "recordsTotal" => $this->locacao->count_all(),
    "recordsFiltered" => $this->locacao->count_filtered(),
    "data" => $data,
        );

  echo json_encode($output);
  }
  }
    
asked by anonymous 23.12.2016 / 15:16

2 answers

0

I HAVE RESOLVED, FOLLOW CODE:

  //ASSIM QUE COMEÇAR A BUSCAR, DIGITAR ALGUMA COISA
  $('.dataTables_filter input').on( 'keyup', function () {
   //PEGA O VALOR DIGITADO
   var value = $('.dataTables_filter input').val();
   //VE SE TEM ALGUM VALOR NO VALOR DIGITADO
  if(value != null && value != " " && value != false){
    //SE TIVER ALGUM VALOR MUDA A QUANTIDADE DE ITEMS EXIBIDO NA PAGINA
    $table.page.len( 10 ).draw();
   // SE NAO TIVER ALGUM VALOR, VOLTA AO NORMAL A QUANTIDADE DE ITEMS 
  }else{
    $table.page.len( 1 ).draw();
  }
  } );
    
24.12.2016 / 15:57
1

You can try to use the preXhr and event of the search or directly in the field or api (_fnFilterCustom if I am not mistaken)

Before starting the search, use the api to remove pagination (bPaginate) when you have some text in the search and add it again when you do not have text

link

link

    
23.12.2016 / 20:03