title: Removing HTML table rows in D3
body: <p>I am using D3.js to dynamically update a HTML table based on data retrieved from an AJAX call in Firefox. It is possible for my array to actually be empty after previously having data (so, this code gets called first with array = [ {...}, {...}, {...}, ... ] and then get called with array = [], and I verified using Firebug that the variable array actually does have these values). When it gets called the second time, I would expect the empty array would cause the code to remove all the rows currently in the table, but that does not happen. Instead, the old data still shows up in the table. Can someone please explain why this code is incorrect (or at least a correct way to do what I want)?</p>
  
  <pre><code>var rows = d3.select(TABLE_BODY_ID)
      .selectAll("tr")
      .data(array, function(d) {
          return d.id;
      });
  rows.enter()
      .append("tr")
      .selectAll("td")
      .data(function() { ... })
      .enter()
      .append("td")
      .each(function(d, i)
      {
          if(3 === i)
          {
              var img = d3.select(this)
                  .append("img");
              img.attr("src", d)
                  .attr("width", 20)
                  .attr("height", 20);
          }
          else d3.select(this).text(function(d) { return d; });
      });
  rows.exit().remove();
  </code></pre>
  
  <p>I use code that is basically identical to this on other tables, and it works with no issues, so I am at a loss as to why it doesn't work for this one table.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT for additional information:</p>
  
  <p>After poking around some more, I found out the code <strong>does</strong> actually work. The reason that the rows still appear in the table is apparently due to the line following it:</p>
  
  <pre><code>$(TABLE_ID).trigger("sorton", [[[1, 1],[2, 1]]]);
  </code></pre>
  
  <p>Apparently, the tablesorter plugin does not play well with D3.js. I am still not certain how to resolve this problem, but I have a few ideas. </p>