【发布时间】:2020-10-05 13:36:04
【问题描述】:
如果我有两种类型的行:
header rows 和 data rows。并且任何行都应该由18 columns组成。
数据行数以表头行数为准,例如:
If I have 2 header rows, I should have (2 datarows: the first one map to the first header row, the second one map to the second header row + 2 datarows: the first one map to the first header row, the second one map to the second header row + 1 data rows for total: maps to the first header row ) = 5 datarows per group
If I have 3 header rows, I should have (3 datarows: the first one map to the first header row, the second one map to the second header row, the third one maps to the third header row + 3 datarows: the first one maps to the first header row, the second one maps to the second header row, the third one mapss to the third header row + 1 for total: maps to the first header row) = 7 datarowsper group
等等
NOTE: ALWAYS I SHOULD HAVE ONE DATA ROW FOR THE TOTAL DATA ROWS.
我想遍历数据行的列并映射到相关的标题col数据:
"render": function (data, type, full, meta) {
let tooltip = isNaN(data) ? data : Number(data);
return type === 'display' ? '<div id="tooltip" data-tooltip="' +parsedData.columns[meta.col].toString().split("-")[0] + " = " + tooltip + "|" + meta.row + '">' + data : data;
}
我们来看第二个例子:我有两个标题行:
parsedData.columns = array[36] where 36 = 2 * 18 = number of header rows * number of columns per row.
There are multiple data rows one array for each data row = one row array[18]
meta.row = row index
我的代码中的问题是,无论标题行有多少,它总是映射到第一个标题行。
为了解决这个问题,我想做一个条件循环。
所以如果the number of header rows = array[36] /18 = 2 标题行:
- 第一个数据行迭代:
parsedData.columns[meta.col].toString().split("-")[0]- 第二次数据行迭代:
parsedData.columns[meta.col-18].toString().split("-")[0]- 第三行数据迭代:
parsedData.columns[meta.col].toString().split("-")[0]- 第四次数据行迭代:
parsedData.columns[meta.col-18].toString().split("-")[0]- 第五个数据行迭代:(总计)所以第一个
parsedData.columns[meta.col].toString().split("-")[0]
and repeat this pattern for each group of row data(5 data rows per group), may I have 3 groups so I have 15 data rows
这里是一个基于 cmets 的例子:
528.00 -->Tooltip should = A1:528.00
52.80 -->Tooltip should = B9:52.80
240.00- -->Tooltip should = B10:240.00-
91.52 -->Tooltip should = T5:91.52
- 本例中的标题行 = 一个数组 [36]
- 数据行是多个数组(5)每个数组=数组[18]
因为我有 2 个标题行 ---> 我有 5 个数据行
2 + 2 + 1(total).
现在我想将数据行中的每个工具提示单元格映射到其等效的标题行,如上图所示。但它总是映射到第一个标题行。
【问题讨论】:
-
您能添加一个示例输入数据集和预期结果吗?
-
你能保证你的输入数据集总是以正确的顺序出现吗?例如
[HR][DR][HR][DR][HR][DR]...[TR]?如果是这样,您可以按其索引处理每一行并评估它是奇数还是偶数。总行将始终排在最后,并且它的索引等于 total-1。 -
@Gigabyte 标题行不与数据行重复。如果我有 2hd,那么根据分组我有 6dr 或 12dr 或 18dr 或 24dr,我想正确地进行映射
-
我也很抱歉,但是没有输入数据和预期结果真的很难帮助你;所以,请永远一次,向我们提供您的输入数据、您的预期结果和您不工作的代码,这样我们就可以停止这个无用的乒乓球并开始为您的问题提供答案。
-
@ShaiCohen :对不起,我编辑了我的问题并添加了一张照片来说明这个想法,总数应该始终=1 行而不是 2 行。
标签: javascript c# jquery loops datatables