function genData() {
var TYear = $("#SearchTYear").val();
var Sheet = $("#SearchSheet").val();
var Summary = $("#SearchSummary").val();
var Dept1 = $("#SearchDept1").prop("checked");
var Dept2 = $("#SearchDept2").prop("checked");
var Dept3 = $("#SearchDept3").prop("checked");
var CostCenter = $("#SearchCostCenter").prop("checked");
$.ajax({
url: '../api/SummaryBudget/Query',
data: { TYear: TYear, Sheet: Sheet, Summary:Summary,Dept1: Dept1, Dept2: Dept2, Dept3: Dept3, CostCenter: CostCenter },
type: 'GET',
cache: false,
dataType: 'json',
async: true,
success: function (data) {
rowcount = data.recordsTotal;
//之前是用表单级绑定,现在想改成表格级绑定,执行到var table = sheet.tables.add('tableRecords', 10, 1, 4, 4)就报错,gc.spread.sheets.all.10.2.0.min.js:49 Uncaught Error: Invalid row index or row count.
var data = data.data;
var tableColumns = [],
names = ['Id','Category', 'Dept1', 'Dept2', 'Dept3', 'Costcenter', 'Input', 'Target', 'Actpy', 'Cf'],
labels = ['Id','Category', 'Dept1', 'Dept2', 'Dept3', 'Costcenter', 'Input', 'Target', 'Actpy', 'Cf'];
var table = sheet.tables.add('tableRecords', 10, 1, 4, 4);
table.autoGenerateColumns(false);
names.forEach(function (name, index) {
var tableColumn = new GC.Spread.Sheets.Tables.TableColumn();
tableColumn.name(labels[index]);
tableColumn.dataField(name);
tableColumns.push(tableColumn);
});
table.bindColumns(tableColumns);
table.bindingPath('sales');
source = new GC.Spread.Sheets.Bindings.CellBindingSource(data);
sheet.setDataSource(source);
/* 之前是用表单级绑定
//var colInfos = [
// { name: 'Category', size: 100 },
// { name: 'Dept1', size: 100 },
// { name: 'Dept2', size: 100 },
// { name: 'Dept3', size: 100 },
// { name: 'Costcenter', size: 100 },
// { name: 'Input', size :100 },
// { name: 'Target', size: 100 },
// { name: 'Actpy', size: 100 },
// { name: 'Cf', size: 100 }
//];
//sheet.autoGenerateColumns = false;
//sheet.setDataSource(data.data);
//sheet.bindColumns(colInfos);
*/
//停止重绘 important!
spread.suspendPaint();
var option = {
allowFilter: true,
allowSort: true,
allowResizeRows: true,
allowResizeColumns: true,
allowEditObjects: false,
allowDragInsertRows: false,
allowDragInsertColumns: false,
allowInsertRows: false,
allowInsertColumns: false,
allowDeleteRows: false,
allowDeleteColumns: false
}
sheet.options.protectionOptions = option;
sheet.options.isProtected = true;
//恢复重绘 important!
spread.resumePaint();
sheet.clearPendingChanges();
$("#loadingCover").hide();
},
error: function (data) {
$("#loadingCover").hide();
}
});
}
|
|