的含量多者是否有可能创建基于单元格的内容的表的N个,例如我有以下表:分割一个表到基于行
<table>
<tr>
<td>Row 1 Colum 1</td>
<td>Row 1 Colum 2</td>
<td>Row 1 Colum 3</td>
<td>1</td>
</tr>
<tr>
<td>Row 2 Colum 1</td>
<td>Row 2 Colum 2</td>
<td>Row 2 Colum 3</td>
<td>2</td>
</tr>
<tr>
<td>Row 3 Colum 1</td>
<td>Row 3 Colum 2</td>
<td>Row 3 Colum 3</td>
<td>2</td>
</tr>
</table>
第四列具有1和2的值,基于这一点,我想创建2个表,每一个不同的号码,在这种情况下图1和2,
结果:
表1
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 1 Colum 1</td>
<td>Row 1 Colum 2</td>
<td>Row 1 Colum 3</td>
<td>1</td>
</tr>
</tbody>
</table>
表2
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row 2 Colum 1</td>
<td>Row 2 Colum 2</td>
<td>Row 2 Colum 3</td>
<td>2</td>
</tr>
<tr>
<td>Row 3 Colum 1</td>
<td>Row 3 Colum 2</td>
<td>Row 3 Colum 3</td>
<td>2</td>
</tr>
</tbody>
</table>
EDIT。
数据是从CSV中提取的,我使用jquery-csv来创建表格。 此CSV具有200列,包含来自不同员工的交易信息,每行显示交易明细,例如员工1有3笔交易,其中2笔交易具有相同的ID,另一笔具有不同的ID:
idEmployee|Transaction|idTransaction|..|..|..|
1 |Buy X thing| 001 |..|..|..|
1 |Buy Y thing| 001 |..|..|..|
1 |Buy Z thing| 002 |..|..|..|
这个表可以有多次交易ID多个员工,我要的是创建一个表中的每个交易编号,例如,最后一个表的结果将是为每个事务ID 2表之一:
TABLE1
idEmployee|Transaction|idTransaction|..|..|..|
1 |Buy X thing| 001 |..|..|..|
1 |Buy Y thing| 001 |..|..|..|
TABLE2
idEmployee|Transaction|idTransaction|..|..|..|
1 |Buy Z thing| 002 |..|..|..|
什么我到目前为止的代码是基于行数一分为二的表:
var rows = $("table").find ("tr").slice(3);
var $tableCopy = $("content").append("<table id='tableCopy'><tbody></tbody></table>");
$tableCopy.find("tbody").append(rows);
$("table").find ("tr").slice(3).remove();
有问题的项目是这样的:用户有一个CSV有大量关于员工的数据,他希望根据CSV信息制作一份报告来打印报告,因此他在页面上输入CSV,然后选择他想要在报告中显示的列,然后系统创建多个报告仅包含用户选择的列,并且因为CSV包含多名员工的信息,系统会创建多个报告。此外,用户可以制作报告的布局,但这是另一天哈哈。
编辑2: 我创建的创建基于的ID的报告的数目的多个表的一些代码,第一I使包含的ID报告总数的数组:
$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();
}
然后我使数基于对数表reportsID的
创建表的功能
$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('<table id=table' + i + '><tbody></tbody>' + '</table>');
}
}
到目前为止,此代码的工作,并创建了numbe现在我只需要填充它,我还没有想法,但我正在处理它哈哈
您尝试过哪些代码来达到此目的? –
从哪里获取数据?这是决定你下一步的重要部分。 例如,如果您使用的是jQuery,则可以遍历自定义数据源的输出,并依次在HTML格式的存储变量中追加必要的数据。然后,只需访问必要的div的innerHTML并在其中存储var的内容。 –
如果你能详述更多,它会更好。 – divy3993