我以一种相当优雅的方式解决了这个问题。
所有将成为dataAdapter一部分的数据,我都会检查复杂对象并对它们进行字符串化。
var data = []; //dataset
data.map( row => {
let x = {};
if (obj.hasOwnProperty(v) && obj[v] && obj[v].constructor === {}.constructor){
x[v] = JSON.stringify(obj[v]);
}else {
x[v] = obj[v];
}
return x;
});
现在数据已经准备好,列已经设置好,我们进入cellsender:
col.cellsrenderer = (index: number, datafield: string, value: any, defaultvalue: any, column: any, rowdata: any): string => {
let decode = value;
try {
decoded = JSON.parse(value);
}catch (e){
decoded = value;
}
//Now you can do custom stuff with a formatter:
let formatter = getFormatter(XXXXX);
let cell = `<div>${formatter.format(decoded)}</div>`;
//decoded would be an object OR a fundamental type string, number, etc.
// When doing cellrenderer, you will only be able to use globalclasses, so custom component based class defintions will not work. If needed, you would use inline styles, or expose global css/scss for a cell.
return cell;
}