title: jQuery DataTables: How do I add a row ID to each dynamically added row?
body: <p><strong>Summary</strong></p>
  
  <p>I am using the great dataTables jQuery plugin from <a href="http://www.datatables.net" rel="nofollow noreferrer">http://www.datatables.net</a>.  In my script, I am dynamically adding rows based on an event firing using <code>fnAddData</code>.  Using <code>fnRowCallback</code>, I add in a unique row ID.  This sometimes fails and does not add a row ID.  In a test of 46 row additions, usually 6 to 8 rows do not get a row ID.</p>
  
  <p><br>
  <strong>Add Row function</strong></p>
  
  <pre><code>function ps_ins(row)
  {
    var rowArray = row.split('|');
    row = rowArray;
    var alarmID = parseInt(row[1],10);
  
    $('#mimicTable').dataTable().fnAddData([
      alarmID, 'col2', 'col3', 'col4',
      'col5', 'col6', 'col7'
    ]);
  }
  </code></pre>
  
  <p>Rows are added to the table correctly.  The test I am running adds 46 rows, and all appear as expected.</p>
  
  <p><br>
  <strong>Add the row ID</strong></p>
  
  <p>I am trying to add a unique ID to each row so I can later modify a specific row and refer to it in dataTable's cache using a combination of fnGetRows and .filter.</p>
  
  <p>I am doing this using fnRowCallback during the initialisation stage.  I've kept all the other settings just incase there's anything there that might have an impact on the problem.</p>
  
  <pre><code>  $('#mimicTable').dataTable({
      "sDom": 'lip&lt;"mimicSpacer"&gt;f&lt;"numUnAck"&gt;rt',
      "sScrollY": "365px",
      "aaSorting": [[4,'desc'],[5,'desc']],
      "iDisplayLength": 15,
      "aLengthMenu": [[15, 50, 100, -1], [15, 50, 100, 'All']],
      "bAutoWidth": false,
      "aoColumns": [
        null,
        { "sWidth": "20%" },
        { "sWidth": "22%" },
        { "sWidth": "9%" },
        { "sWidth": "9%" },
        { "sWidth": "20%" },
        { "sWidth": "20%" }
      ],
      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        $(nRow).attr("id",'alarmNum' + aData[0]);
        return nRow;
      }
    });
  </code></pre>
  
  <p>A <code>console.log</code> of the dataTable object shows:
  <img src="https://i.stack.imgur.com/B5bnG.png" alt="missing row ids"></p>
  
  <p>As you can see, #14 has the row id and also the correct rowStripe class.  #15 (and onwards) doesn't.</p>
  
  <p><strong>So, why is fnRowCallback not firing each time a row is added, only sometimes?  Maybe there is a better way to add a row ID when a row is added?</strong></p>