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

Asked

Viewed 743 times

0

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

Some 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 metodh:

  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);
  }
  }

2 answers

1

  • tried this way but unsuccessfully so far:

  • var oSettings = $table.fnSettings(); oSettings.bPaginate = false; $table.draw();

  • $table.on('search.dt', Function() { var value = $('. dataTables_filter input'). val(); Alert(value); });

0


I managed to solve, it follows 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();
  }
  } );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.