mardi 21 mai 2019

Adding button intot table javascript

I'm trying to add 'Download' button into a table, but some of the buttons returns null, and than i have error :"Cannot set property 'onclick' of null".

JS CODE:

 var table = $('#dataTables-example').DataTable();
 ref.on("value", function(snapshot) {
 snapshot.forEach(function(childSnapshot) {
  var childData = childSnapshot.val();
  var number = childData.ParNumber;
  var numOfTr = childData.NumOfTry;
  var startTime = childData.startTime;
  numberofbutton = Math.random();
  table.row.add( [
      coursrNum,
      number,
      numOfTr,
      startTime,
    '<button id =' numberofbutton'>Download File</button>'
  ] ).draw( false );
     var button = document.getElementById(numberofbutton);
     button.onclick = function(){ myScript(number+'_'+numOfTr)};
    });

});




Aucun commentaire:

Enregistrer un commentaire