title: Split one table into multiple ones based on content of a row
body: <p>Is it possible to create N number of tables based on the content of cell, for example I have the following table:</p>
  
  <pre><code>  &lt;table&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 1 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 1 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 1 Colum 3&lt;/td&gt;
        &lt;td&gt;1&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 2 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 2 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 2 Colum 3&lt;/td&gt;
        &lt;td&gt;2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 3 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 3 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 3 Colum 3&lt;/td&gt;
        &lt;td&gt;2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p>The fourth column has a 1 and 2 values, based on that, I want to create 2 tables, one for each different number, in this case 1 and 2, </p>
  
  <p>Result:</p>
  
  <p>TABLE 1</p>
  
  <pre><code>  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Column 1&lt;/th&gt;
        &lt;th&gt;Column 2&lt;/th&gt;
        &lt;th&gt;Column 3&lt;/th&gt;
        &lt;th&gt;Column 4&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 1 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 1 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 1 Colum 3&lt;/td&gt;
        &lt;td&gt;1&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p>TABLE 2</p>
  
  <pre><code>  &lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Column 1&lt;/th&gt;
        &lt;th&gt;Column 2&lt;/th&gt;
        &lt;th&gt;Column 3&lt;/th&gt;
        &lt;th&gt;Column 4&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 2 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 2 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 2 Colum 3&lt;/td&gt;
        &lt;td&gt;2&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Row 3 Colum 1&lt;/td&gt;
        &lt;td&gt;Row 3 Colum 2&lt;/td&gt; 
        &lt;td&gt;Row 3 Colum 3&lt;/td&gt;
        &lt;td&gt;2&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
    &lt;/table&gt;
  </code></pre>
  
  <p>EDIT.</p>
  
  <p>The Data is fetched from a CSV, I'm using <a href="https://github.com/evanplaice/jquery-csv" rel="nofollow">jquery-csv</a> to create the table.
  This CSV has like 200 columns with info about transactions from different employees, each row shows a transaction detail, for example employee 1 has 3 transactions, 2 of that transactions have the same id, the other one has a different id:</p>
  
  <pre><code>idEmployee|Transaction|idTransaction|..|..|..|
      1     |Buy X thing|      001    |..|..|..|
      1     |Buy Y thing|      001    |..|..|..|
      1     |Buy Z thing|      002    |..|..|..|
  </code></pre>
  
  <p>This table can have multiple employees with multiple transactions id, what I want is create a table for each transaction number, for example, the result of the last table will be 2 tables one for each transaction id:</p>
  
  <p>TABLE1</p>
  
  <pre><code>idEmployee|Transaction|idTransaction|..|..|..|
      1     |Buy X thing|      001    |..|..|..|
      1     |Buy Y thing|      001    |..|..|..|
  </code></pre>
  
  <p>TABLE2</p>
  
  <pre><code>idEmployee|Transaction|idTransaction|..|..|..|
      1     |Buy Z thing|      002    |..|..|..|
  </code></pre>
  
  <p>What I have so far in code is to split a table in two based on the number of rows:</p>
  
  <pre><code>var rows = $("table").find ("tr").slice(3);
  var $tableCopy = $("content").append("&lt;table id='tableCopy'&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;");
  $tableCopy.find("tbody").append(rows);
  $("table").find ("tr").slice(3).remove();
  </code></pre>
  
  <p>The project in question is this: A user have a CSV with a lots of data about employees, and he wants to make a report based on the CSV info to print it, so he enters the CSV on the page, then selects the columns he wants to display on the report, the system then creates multiple reports with only the columns the user selected and because the CSV had info for multiple employees, the system creates multiple reports. Also, the user can make the layout of the report, but that's for another day haha.</p>
  
  <p>Edit 2:
  I created some code that creates multiple tables based on the number of id reports, first I make an array that contains the total number of id reports:</p>
  
  <pre><code>  $scope.getReportsID = function(){
      $scope.reportsID = [];
      //Loop through the array data that contains the table
      for(var row in $scope.data){
      //Loop through the specific cell
        for(var item in $scope.data[row]){
          //The reportID is on cell 19, if that id exist on the array 
          //break the loop but if doesn't exist, check if the data is not 
          //an empty string, if not, push the data on the array
          if((jQuery.inArray( $scope.data[row][19], $scope.reportsID )) !== -1)
            break;
          if($scope.data[row][19] !== "")
            $scope.reportsID.push($scope.data[row][19]);
        }
      }
      //We call createTables function
      $scope.createTables();
    }
  </code></pre>
  
  <p>Then I make the number of tables based on the number of reportsID's</p>
  
  <p>CREATE TABLES function</p>
  
  <pre><code>  $scope.createTables = function() {
      //Loop through the array that contains the diferent reporst id's
      for(var i in $scope.reportsID){
        //Loop through the array data that contains the table
        for(var row in $scope.data){
           //If data on the cell 19 of the current row equals the current 
           //element of the reportsID array,break the loop and create a table
          if( $scope.data[row][19] === $scope.reportsID[i])
            break;
        }
        $('#hereTables').append('&lt;table id=table' + i + '&gt;&lt;tbody&gt;&lt;/tbody&gt;' + '&lt;/table&gt;');
      }
    }
  </code></pre>
  
  <p>So far this code works and creates the number of tables equal to the number of different id's, now I just need to fill it, I have no idea yet, but I'm working on it haha</p>