function importJson(spreadJson) {
function updateActiveCells() {
for (var i = 0; i < spread.getSheetCount(); i++) {
var sheet = spread.getSheet(i);
columnIndex = sheet.getActiveColumnIndex(),
rowIndex = sheet.getActiveRowIndex();
if (columnIndex !== undefined && rowIndex !== undefined) {
spread.getSheet(i).setActiveCell(rowIndex, columnIndex);
} else {
spread.getSheet(i).setActiveCell(0, 0);
}
}
}
if (spreadJson.sheets) {
spread.unbindAll();
spread.fromJSON(spreadJson);
attachSpreadEvents(true);
updateActiveCells();
spread.focus();
// fbx.workbook(spread);
onCellSelected();
syncSpreadPropertyValues();
syncSheetPropertyValues();
initSpreadEx();
} else {
alert(getResource("messages.invalidImportFile"));
}
}
function initSpreadEx() {
function BindingPathCellType() {
spreadNS.CellTypes.Text.call(this);
}
BindingPathCellType.prototype = new spreadNS.CellTypes.Text();
BindingPathCellType.prototype.paint = function(ctx, value, x, y, w, h, style, context) {
if (location_setting.show_binding && (value === null || value === undefined)) {
var sheet = context.sheet,
row = context.row,
col = context.col;
if (sheet && (row === 0 || !!row) && (col === 0 || !!col)) {
var bindingPath = sheet.getBindingPath(context.row, context.col);
if (bindingPath) {
value = "[" + bindingPath + "]";
}
}
}
spreadNS.CellTypes.Text.prototype.paint.apply(this, arguments);
};
var bindingPathCellType = new BindingPathCellType();
var activespread = spread.getActiveSheet();
var rowCount = activespread.getRowCount();
var columnCount = activespread.getColumnCount();
for(var i = 0;i<rowCount;i++) {
for (var j = 0; j < columnCount; j++) {
var bindingPath = activespread.getBindingPath(i, j);
if (bindingPath) {
if(SPREAD.bindingData == false) {
activespread.getCell(i, j).bindingPath(bindingPath).cellType(bindingPathCellType);
}
}
};
};
$("#changeDataSource").click(function() {
zTreeOnClick();
});
$("#initdata").click(function() {
initData();
});
$("#removebind").click(function() {
removebind();
});
initTree();
var zTreeObj;
var setting;
var data;
var zTreeObj;
function initTree(){
tempget(function (ordata) {
setting = {
view:{
selectedMulti: false
},
callback: {
onDblClick: zTreeOnClick,
},
data: {
simpleData: {
enable: true
},
key: {
title: "description"
}
}
};
var treedata = [];
var tempmaintable = []
for (var i in ordata["tableData"]) {
var isShow = ordata["tableData"]["isShow"] == "Y" ? true : false;
if(isShow){
var temp = {"name"rdata["tableData"]["fieldName"],"type"rdata["tableData"]["type"],"description"rdata["tableData"]["content"],"showType"rdata["tableData"]["showType"],"canchoos":"true"};
tempmaintable.push(temp);
}
}
treedata.push({"name":"tableData","type":"tableData","description":"tableData","showType":"tableData","children":tempmaintable,"canchoos":"flase"});
tempmaintable = []
for (var i in ordata["subTableDate"]) {
var tempmain = {"name":i,"type":"table","description":"table","showType":"table","canchoos":"true"};
var tempsub =[];
for (var j in ordata["subTableDate"]) {
var isShow = ordata["subTableDate"][j]["isShow"] == "Y" ? true : false;
if(isShow){
var temp = {"name"rdata["subTableDate"][j]["fieldName"],"type"rdata["subTableDate"][j]["type"],"description"rdata["subTableDate"][j]["content"],"showType"rdata["subTableDate"][j]["showType"],"canchoos":"true"};
tempsub.push(temp);
}
};
tempmain["children"]=tempsub
tempmaintable.push(tempmain);
}
treedata.push({"name":"subTableData","type":"subTableData","description":"subTableData","showType":"subTableData","children":tempmaintable,"canchoos":"flase"});
zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, treedata);
});
spread.resumePaint();
};
function initData() {
var activespread = spread.getActiveSheet();
var rowCount = activespread.getRowCount();
var columnCount = activespread.getColumnCount();
for(var i = 0;i<rowCount;i++) {
for (var j = 0; j < columnCount; j++) {
var bindingPath = activespread.getBindingPath(i, j);
if (bindingPath) {
if(SPREAD.bindingData == true && bindingPath == "tableData.fenbu_fenxiangid" )
{
activespread.setValue(i, j, "IDDDSAASD");
}
}
};
};
};
function zTreeOnClick() {
var sheet = spread.getActiveSheet();
var selectioncells = sheet.getSelections();
var nodes = zTreeObj.getSelectedNodes();
SetData(sheet,selectioncells,nodes,bindingPathCellType);
};
function removebind(){
var sheet = spread.getActiveSheet();
var selectioncells = sheet.getSelections();
bindremove(sheet,selectioncells,bindingPathCellType);
};
var sheet = spread.getActiveSheet();
var path = "";
$("#bindingPath").text(path || "");
sheet.bind(spreadNS.Events.SelectionChanged, function() {
var activeCell = sheet.getSelections()[0];
var path = sheet.getBindingPath(activeCell.row, activeCell.col);
$("#bindingPath").text(path || "");
});
sheet.resumePaint();
};
|