problem with data table when data is append with ajax,sorting and searching is not working....

problem with data table when data is append with ajax,sorting and searching is not working....

krishnareddykrishnareddy Posts: 2Questions: 1Answers: 0
edited May 2016 in Free community support

problem with data table when data is append with ajax,sorting and searching is not working....

function users() {
var table;
//reinitialise the dataTable
table = $('#sample_1').DataTable({
destroy: true,
bLengthChange: false,
paging: false,
});
$.ajax({
type: "POST",
url: "<?php echo base_url('admin/users'); ?>",
data: 'id='+id,
dataType: 'json',
cache: false,
success: function(data) {
if(data!='') {
var trdata="";
$.each(data, function(i, item) {
trdata+='<tr><td><img alt="User Pic" class="img" src="<?php echo base_url(); ?>assets/user_pics/'+data[i].user_pic+'" width="50px"></td><td>'+data[i].user_name+'</td><td>'+data[i].user_phone+'</td><td>'+data[i].user_email+'</td><td>'+data[i].avgvisits+'</td></tr>';
});

            $('#display_customers').append(trdata);
            } else {
            trdata='<tr><td colspan="7"><h3>No customers are available</h3></td></tr>';
            $('#display_customers').html(trdata); 
            }

            table.Draw();

         }
   });

   }

Answers

  • krishnareddykrishnareddy Posts: 2Questions: 1Answers: 0
    edited May 2016

    i got solutions of above post, i tried bellow code, it working fine..........., thanks you

       function users() {
        $.ajax({
                type: "POST",
                url: "<?php echo base_url('admin/users'); ?>",
                data: 'id='+id,
               dataType: 'json',
                cache: false,
                success: function(data) {
                  var table;
                table = $('#sample_1').DataTable();     
                if(data!='') {                
                 $.each(data, function(i, item) {
                    table.row.add([ data[i].user_name, data[i].user_phone, data[i].user_email ]);
                });               
                } 
                else {
                $('#sample_1').html('<h3>No users are available</h3>'); 
                }
                table.draw();
             }
       });
       }
    
This discussion has been closed.