in packages/tablesorter-powerbi/src/ConfigBuilder.ts [54:106]
export default function(
dataView: powerbi.DataView,
data: ITableSorterRow[],
colorSettings: IColorSettings,
resetRankLayout = true,
reverseRankingColumns = false): ITableSorterConfiguration {
"use strict";
if (dataView) {
// Initially parse all of the columns from the data view so we know the valid columns
let validColumns = parseColumnsFromDataView(dataView, data);
// Attempt to load the existing table sorter config from powerbi
let config: ITableSorterConfiguration;
if (dataView.metadata && dataView.metadata.objects && dataView.metadata.objects["layout"]) {
const configStr = dataView.metadata.objects["layout"]["layout"];
if (configStr) {
config = JSON.parse(configStr as string);
}
}
// Generate the "rank" columns and append them to the set of valid columns
const rankResult = parseRankColumns(dataView, colorSettings, reverseRankingColumns);
if (rankResult) {
validColumns.some(c => {
if (c.column === rankResult.info.column.displayName) {
c.type = "string";
delete c["domain"];
return true;
}
});
validColumns = validColumns.concat(rankResult.columns);
}
// If we don't have a config, then just create a simple one
if (!config) {
config = {
primaryKey: validColumns[0].label,
columns: validColumns,
};
} else {
// Otherwise we need to do some additional processing
processExistingConfig(config, validColumns);
}
// Process the configuration with the current rank information
processConfigWithRankResult(config, rankResult, resetRankLayout);
return config;
}
}