找回密码
 立即注册

QQ登录

只需一步,快速开始

yhjsbok

注册会员

8

主题

27

帖子

184

积分

注册会员

积分
184
yhjsbok
注册会员   /  发表于:2018-8-23 09:19  /   查看:3374  /  回复:4
        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();
                }
            });

        }

4 个回复

倒序浏览
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-8-23 11:00:21
沙发
您是不是修改过行数和列数,报这个错误应该是表格超行数列数了,但是默认spreadjs初始化时行数是200行列数是20列是足够的。所以您可以在添加表格之前用sheet.getRowCount和sheet.getColumnCount看一下行数和列数是否能够满足添加。
另外您电话问的另一个问题,能够导出列头,可以在toJSON的时候设置columnHeadersAsFrozenRows:true
像这样:
spread.toJSON({includeBindingSource:true,columnHeadersAsFrozenRows:true});
回复 使用道具 举报
yhjsbok
注册会员   /  发表于:2018-8-23 15:01:18
板凳
ClarkPan 发表于 2018-8-23 11:00
您是不是修改过行数和列数,报这个错误应该是表格超行数列数了,但是默认spreadjs初始化时行数是200行列数 ...

Uncaught TypeError: b.split is not a function 现在报这个错
WeChat 圖片_20180823150052.png
回复 使用道具 举报
yhjsbok
注册会员   /  发表于:2018-8-23 15:35:36
地板
ClarkPan 发表于 2018-8-23 11:00
您是不是修改过行数和列数,报这个错误应该是表格超行数列数了,但是默认spreadjs初始化时行数是200行列数 ...

{"draw":1,"recordsTotal":2,"recordsFiltered":2,"data":[{"Id":1,"Category":"DFC","Costcenter":"36980000","Dept1":"CN1","Dept2":"CN2","Dept3":"CN3","Input":4,"Target":0,"Actpy":0,"Cf":0,"Ytd":0},{"Id":2,"Category":"IT","Costcenter":"36980000","Dept1":"CN1","Dept2":"CN2","Dept3":"CN3","Input":2,"Target":0,"Actpy":0,"Cf":0,"Ytd":0}]}
回复 使用道具 举报
Clark.Pan讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2018-8-23 18:51:55
5#
参考附件

bindDataSource - 副本.html

2.16 KB, 下载次数: 148

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部