数据表填充所有行,但显示“ 1个条目中的1个”

时间:2018-08-07 01:12:13

标签: jquery ajax datatables

我正在尝试使用从我的API收集的信息填充数据表。目前,我能够用所需的所有行填充表,但是除了第一个结果外,它们似乎没有附加到表上。如果进行任何搜索,这将导致数据表仅显示1个条目。底部还会显示“显示1项中的1项至1项”

Fiddle

JS

plt.xlim(1, 10)
plt.ylim(1, 10)

1 个答案:

答案 0 :(得分:0)

这是更新的代码Fiddle/5

您太早初始化Datatable了:在添加所有行之前。在将所有数据附加到DOM HTML之后,您需要对其进行初始化。

//Payment history
$.ajax({
  url: "https://zelcash.voidr.net/api/payments",
  dataType: 'json',
  success: function(data) {

    var _miner = "t1XHpNtYY2N3EMDRoX9RM2hq4DWWPZSmawJ";

    var addr = _miner;

    for (var i = 0; i < data.length; i++) {

      //Name
      console.log(data[i].name);

      var payments = data[i].payments;
      for (var j = 0; j < payments.length; j++) {

        if (payments[j].amounts[_miner]) {

          //Time
          //console.log(payments[j].time);
          var date = payments[j].time;
          var date = new Date(parseInt(date));
          var date = date.toGMTString();

          //blocks
          var block = [];
          var blocks = payments[j].blocks;
          for (var b = 0; b < blocks.length; b++) {
            //console.log(blocks[b])
            block.push(blocks[b]);
          }

          //txid
          var txid = payments[j].txid;

          //amount
          //console.log(payments[j].amounts[_miner]);
          var amount = payments[j].amounts[_miner].toFixed(8);

          var htmlToAdd = "";
          htmlToAdd = '<tr>';
          htmlToAdd+= '<td>'+block+'</td>';
          htmlToAdd+= '<td><a href=\"https://explorer.zel.cash/tx/'+txid+'\">'+amount+'</a></td>';
          htmlToAdd+= '<td>'+date+'</td>';
          htmlToAdd+= '</tr>';
          $("#boxesPayments").html($("#boxesPayments").html()+htmlToAdd);


        }
      }

                $('#paymentTable').DataTable();
    }

  },
  error: function() {
    //alert("Was unable to get info!");
  }
});