将行名称添加到 cde table 组件
Add row name to cde table component
我的 Pentaho CDE 仪表板中有一个 table 组件,数据源是 sql。我想做一个这样的 table
我需要为此 table 添加一列作为行名称,并在列 header 的顶部添加一行。
我在这里找到了一个方法:
Table Component SubColumns
添加 header,但如何在其他列之前添加一列?
我认为执行额外列部分的一个聪明方法是在从查询中检索到查询结果对象后修改它,以便您根据需要添加列和行。您可以在 PostFetch
回调函数中执行此操作,该函数将查询结果对象作为第一个参数:
function yourTableComponentPostFetch(queryResult) {
// Let's say you have an array of row names
var rowNames = ['Title1', 'Title2', ... ];
// Add a "title" column for every row
queryResult.resultset.forEach(function (row, idx) {
// Push it at the beginning of the row array
row.unshift(rowNames[idx]);
});
// Change metadata description of columns to reflect this new structure
queryResult.metadata.unshift({
colName: 'Title',
colIndex: -1, // this makes sense when reindexing columns below ;)
colType: 'String'
});
// One last re-indexing of metadata column descriptions
queryResult.metadata.forEach(function (column, idx) {
// The title added column will be 0, and the rest will rearrange
column.colIndex++;
});
}
唯一棘手的部分是关于修改元数据的部分,因为您正在有效地更改数据集的结构,并确保就地更新 queryResult 对象而不是仅仅更改其引用(queryResult = myNewQueryResult
行不通),但我建议的代码应该可以解决问题。
我的 Pentaho CDE 仪表板中有一个 table 组件,数据源是 sql。我想做一个这样的 table
我需要为此 table 添加一列作为行名称,并在列 header 的顶部添加一行。 我在这里找到了一个方法: Table Component SubColumns 添加 header,但如何在其他列之前添加一列?
我认为执行额外列部分的一个聪明方法是在从查询中检索到查询结果对象后修改它,以便您根据需要添加列和行。您可以在 PostFetch
回调函数中执行此操作,该函数将查询结果对象作为第一个参数:
function yourTableComponentPostFetch(queryResult) {
// Let's say you have an array of row names
var rowNames = ['Title1', 'Title2', ... ];
// Add a "title" column for every row
queryResult.resultset.forEach(function (row, idx) {
// Push it at the beginning of the row array
row.unshift(rowNames[idx]);
});
// Change metadata description of columns to reflect this new structure
queryResult.metadata.unshift({
colName: 'Title',
colIndex: -1, // this makes sense when reindexing columns below ;)
colType: 'String'
});
// One last re-indexing of metadata column descriptions
queryResult.metadata.forEach(function (column, idx) {
// The title added column will be 0, and the rest will rearrange
column.colIndex++;
});
}
唯一棘手的部分是关于修改元数据的部分,因为您正在有效地更改数据集的结构,并确保就地更新 queryResult 对象而不是仅仅更改其引用(queryResult = myNewQueryResult
行不通),但我建议的代码应该可以解决问题。