jqxGrid 是否可以渲染作为对象的单元格值?
例如在此Codepen example每行都有一个属性details
,它有一个对象值。我想说的是,创建一个自定义渲染器来显示它的 JSON 字符串化版本,并创建一个自定义编辑器来修改它。
挑战在于行值显示为字符串“[Object object]”
:
var rows = [
{ color: "red", details: { a: 1, b: 2 } },
{ color: "green", details: { a: 2, b: 4 } },
{ color: "blue", details: { a: 3, b: 8 } },
{ color: "yellow", details: { a: 4, b: 16 } }
];
我尝试创建一个单元格渲染器,但在调用该函数时,参数value
已被压缩为字符串“[Object object]”
。我需要对数据适配器执行某些操作才能获取对象值吗?
var cellsrenderer = function(row, column, value) {
console.log(value);
return "<div>" + JSON.stringify(value) + "</div>";
};
var columns = [
{
text: "Color",
datafield: "color",
width: 100
},
{
text: "Details",
datafield: "details",
width: 200,
cellsrenderer: cellsrenderer
}
];
var source = {
localdata: rows,
datatype: "array"
};
var dataAdapter = new $.jqx.dataAdapter(source, {
loadComplete: function(data) {},
loadError: function(xhr, status, error) {}
});
$("#grid").jqxGrid({
height: 600,
width: 600,
source: dataAdapter,
pageable: true,
pagesize: 20,
autoheight: true,
columns: columns
});
最佳答案
试试这个
var rows = [
{ color: "red", details: [{ a: 1, b: 2 }] },
{ color: "green", details: [{ a: 2, b: 4 }] },
{ color: "blue", details: [{ a: 3, b: 8 }] },
{ color: "yellow", details: [{ a: 4, b: 16 }] }
];
关于javascript - 使用 jqxGrid 渲染作为对象的单元格值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52635918/