简体   繁体   English

有什么方法可以重新加载或刷新数据表中的数据吗?

[英]Is there any way to reload or refresh a data table data?

I have a problem about data tables which is duplication of data rows when triggering a button that refresh the data table datas. 我有一个关于数据表的问题,当触发刷新数据表数据的按钮时,它是数据行的重复。 I tried some code like $("#table").ajax.reload(); 我尝试了一些代码,例如$(“#table”)。ajax.reload();。 and $("#table").empty(); 和$(“#table”)。empty(); but non of those solve my problem 但是这些都不解决我的问题

    $.ajax({
            url: "<?php echo base_url('Dashboard/LatestCheckin'); ?>",
            data: {},
            type: "POST",
            success: function(data) {
                result = JSON.parse(data);
            var table = $('#latest-checkin-table').DataTable();  


            if(result!='') {        

                $.each(result, function(i, item) {
                  var a =  table.row.add([
          result[i].count 
          ,result[i].full_name 
          ,result[i].room_no 
          ,result[i].total_price 
          ,result[i].checkin_date
                    ]).draw();
                });    

            } else {
                $('#latest-checkin-table').html('<h3>No users are available</h3>');
            }

        }
    });

You have to do this: 您必须这样做:

table.clear();
$.each(result, function(i, item) {
                  var a =  table.row.add([
          result[i].count 
          ,result[i].full_name 
          ,result[i].room_no 
          ,result[i].total_price 
          ,result[i].checkin_date
                    ]);
                });
table.draw();

hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM