dimanche 31 mars 2019

How to paginate the results from ajax call?

I had queried data using ajax in Laravel 5.

This is the code to display the result:

  <script type="text/javascript">
      $( "#cari" ).click(function() {
        // alert($('#kategori').val());
        var seksyen = $("#section").val();
        var status_pro= $("#statuspro").val();
        var kategori_id= $("#kategori").val();
        var pangkat_id= $("#pangkat").val();
        var bangsa_id= $("#bangsa").val();
        var agama_id= $("#agama").val();
        var jantina_id= $("#jantina").val();
        var negeri_id= $("#negeri").val();
        var kahwin_id= $("#status_kahwin").val();
         $.ajax({
            url: '?'+ $.param({'section': seksyen,'statuspro': status_pro,'bangsa': bangsa_id,'agama': agama_id,'jantina': jantina_id,'negeri': negeri_id,'status_kahwin': kahwin_id,'kategori': kategori_id,'pangkat': pangkat_id}),
            dataType: 'json',
            success: function (data) {
                console.log(data);
                $('#datatable tr').not(':first').remove();
                var html = '';
                for(var i = 0; i < data.length; i++){
                    html += '<tr>'+
                                '<td>' + data[i].name + '</td>' +
                                '<td>' + data[i].sectionname + '</td>' +
                                '<td>' + data[i].categoryname + '</td>' +
                                '<td>' + data[i].operasiname + '</td>' +
                                '<td>' + data[i].Nobadan + '</td>' +
                                '<td class="text-center">' + '<a href="/'+ data[i].ItemRegistrationID +'">' + '<i class="fa fa-folder fa-fw" rel="tooltip" title="view profil">'+'</i>'+'</a>' + '</td>' +
                            '</tr>';
                    }   
                $('#datatable tr').first().after(html);
            },
            error: function (data) {
            }
        });
      });
  </script>

The code for the table is as follows:

 <table class="table table-striped table-bordered" id="datatable" >
         <tr>
            <th>Nama</th>
            <th>Seksyen</th>
            <th>Kategori</th>
            <th>Pangkat</th>
            <th>No Personal</th>
            <th>Action</th>
         </tr>
</table>

But the results will display a long list of names. How to modify the codes to paginate the results displayed?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire