当属性是另一个对象时如何在jspreadsheet ce中指定column和data属性

问题描述 投票:0回答:1

外部对象具有名称、id、年龄和公司属性。公司属性是另一个具有属性名称和位置的对象。

var table = jexcel(document.getElementById('spreadsheet'), {        
data:[
    { name:'Jorge', id:'3', age:'40',company:{name:'nokia',location:'us'} },
    { name:'Robert', id:'4', age:'48',company:{name:'nokia',location:'us'} },
    { name:'Santos', id:'5', age:'32',company:{name:'nokia',location:'us'} },
],
columns: [
    { type:'text', width:300, name:'id', title:'id' },
    { type:'text', width:100, name:'name', title:'name' },
    { type:'text', width:100, name:'age', title:'age' },
    { type:'text', width:100, data:'company.name', title:'company name' },
    { type:'text', width:100, data:'company.location', title:'company location' },
 ]
});

结果表如下所示: enter image description here

此问题的示例:https://jsfiddle.net/sridharnetha/vf0tknxb/2/

javascript jquery jexcelapi jexceljs jspreadsheet-ce
1个回答
0
投票

使用方法自定义脚本

updateTable
正在按我的预期工作。

data = [
    { name:'Jorge', id:'3', age:'40',company:{name:'nokia',location:'us'} },
    { name:'Robert', id:'4', age:'48',company:{name:'nokia',location:'us'} },
    { name:'Santos', id:'5', age:'32',company:{name:'nokia',location:'us'} },
];

jspreadsheet(document.getElementById('my-spreadsheet'), {
data:data,
allowInsertColumn: false,
columns: [
    { type:'text', width:50, name:'id', title:'id' },
    { type:'text', width:100, name:'name', title:'name' },
    { type:'text', width:50, name:'age', title:'age' },        
    { type:'object', width:100, data:'company.name', title:'company name' },
    { type:'text', width:100, data:'company.location', title:'company location' },
 ],
 updateTable:function(instance, cell, col, row, val, label, cellName) {
 if (col == 3) {
       //alert(JSON.stringify(val));
        cell.innerHTML = val.name;
    }
   }
});
© www.soinside.com 2019 - 2024. All rights reserved.