找回密码
 立即注册

QQ登录

只需一步,快速开始

oscartian

注册会员

5

主题

18

帖子

63

积分

注册会员

积分
63
oscartian
注册会员   /  发表于:2022-3-5 16:34  /   查看:2440  /  回复:12
1金币
本帖最后由 Derrick.Jiao 于 2022-3-7 16:16 编辑

利用管网例子,集算表结合关系视图,初始加载的时候是这样的如下图所示: image.png265868834.png
等到随便更改任何一个单元格的值以后,就可以全部加载出来,如下图所示:
image.png209915465.png
代码如下:


/*REPLACE_MARKER*/
/*DO NOT DELETE THESE COMMENTS*/
<template>
  <div class="sample-tutorial">
    <gc-spread-sheets
      class="sample-spreadsheets"
      @workbookInitialized="initSpread"
    >
    </gc-spread-sheets>
    <div id="options-container" class="options-container">
        <fieldset>
            <legend>Active Row Operations</legend>
            <div class="field-line">
                <input id="remove" type="button" value="Remove" @click="removeRow()">
            </div>
            <div class="field-line">
                <input id="save" type="button" value="Save" @click="saveRow()">
            </div>
            <div class="field-line">
                <input id="reset" type="button" value="Reset" @click="resetRow()">
            </div>
        </fieldset>
        <fieldset>
            <legend>Save All Rows</legend>
            <div class="field-line">
                <input id="save-all" type="button" value="Save All" @click="saveAllRows()">
            </div>
        </fieldset>
        <fieldset>
            <legend>Batch Operations</legend>
            <div class="field-line">
                <input type="button" value="Submit" id="submit" @click="submitChanges()">
            </div>
            <div class="field-line">
                <input type="button" value="Discard" id="discard" @click="discardChanges()">
            </div>
        </fieldset>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import "@grapecity/spread-sheets-vue";
import GC from "@grapecity/spread-sheets";
import "@grapecity/spread-sheets-tablesheet";
import '@grapecity/spread-sheets-resources-zh';
GC.Spread.Common.CultureManager.culture("zh-cn");
import "./styles.css";

var tableName = "Employee";
var baseApiUrl = getBaseApiUrl();
var apiUrl = baseApiUrl + "/" + tableName;
var batchApiUrl = baseApiUrl + "/" + tableName + 'Collection';
var tablesheetName = 'MyTableSheet';

let App = Vue.extend({
  name: "app",
  data: function() {
    return {
        spread: null,
        tablesheet: null,
        selections: null
    }
  },
  methods: {
    initSpread: function (spread) {
        this.spread = spread;

        spread.suspendPaint();
        spread.clearSheets();
        spread.options.autoFitType = GC.Spread.Sheets.AutoFitType.cellWithHeader;
        //init a data manager
        var dataManager = spread.dataManager();
        var myTable = dataManager.addTable("myTable", {
            remote: {
                read: {
                    url: apiUrl
                },
                update: {
                    url: apiUrl,
                    method: 'PUT'
                },
                create: {
                    url: apiUrl
                },
                delete: {
                    url: apiUrl
                },
                batch: {
                    url: batchApiUrl
                }
            },
            batch: true
        });

        var customerTable = dataManager.addTable("customerTable", {
                remote: {
                    read: {
                        url: baseApiUrl + "/Product"
                    }
                }
            });
            //add relationship between order table and customer table
            dataManager.addRelationship(myTable, "Id", "customer", customerTable, "Id", "myTables");


        //init a table sheet
        var sheet = spread.addSheetTab(0, tablesheetName, GC.Spread.Sheets.SheetType.tableSheet);
        // sheet.setColumnVisible(2, false);
        this.tablesheet = sheet;
        var rowActions = GC.Spread.Sheets.TableSheet.BuiltInRowActions;
        var options = sheet.rowActionOptions();
        options.push(
            rowActions.removeRow,
            rowActions.saveRow,
            rowActions.resetRow,
        );
        sheet.rowActionOptions(options);

        var selectView = customerTable.addView("customersView",
                [
                    { value: 'Id' },
                    { value: 'ProductName' },
                ]);
            var multiSelectStyle = {
                formatter: '=CONCAT(PROPERTY(@, "Id"), ", ", PROPERTY(@, "ProductName"))', // convert the object to string
                cellButtons: [
                    {
                        imageType: "dropdown",
                        command: "openMultiColumn",
                        useButtonStyle: true,
                    }
                ],
                dropDowns: [
                    {
                        type: "multiColumn",
                        option: {
                            width: 400,
                            height: 400,
                            dataSource: selectView,
                            bindingInfos: [
                                { name: "Id", size: 60 },
                                { name: "ProductName", size: "*" },
                                // { name: "ContactName", size: "*" },
                            ]
                        }
                    }
                ]
            };

        //bind a view to the table sheet
        myTable.fetch().then(function() {
            var view = myTable.addView("myView", [
                { value: "Id", width: 50, caption: "ID" },
                { value: "FirstName", width: 100, caption: "First Name" },

                 { value: "customer", width: 150, style: multiSelectStyle},
                { value: "LastName", width: 100, caption: "Last Name" },
                { value: "HomePhone", width: 100, caption: "Phone" },
                { value: "Notes", width: 100, caption: "Notes" }
            ]); //the View has all default columns of the Table
            sheet.setDataView(view);
        });

        spread.bind(GC.Spread.Sheets.Events.SelectionChanged, (e, args) => {
            this.selections = args.newSelections;
        });

        spread.resumePaint();
    },

    removeRow() {
        this.traverseSelectionsRowsWithOperation((row) => {
            this.tablesheet.removeRow(row);
        });
    },

    saveRow() {
        this.traverseSelectionsRowsWithOperation((row) => {
            this.tablesheet.saveRow(row);
        });
    },

    resetRow() {
        this.traverseSelectionsRowsWithOperation((row) => {
            this.tablesheet.resetRow(row);
        });
    },

    saveAllRows() {
        this.spread.commandManager().SaveAll.execute(this.spread, { sheetName: tablesheetName });
    },

    submitChanges() {
        this.tablesheet.submitChanges();
    },

    discardChanges() {
        this.tablesheet.cancelChanges();
    },

    traverseSelectionsRowsWithOperation(operation) {
        var selections = this.selections;
        if (selections) {
            for (var i = 0; i < selections.length; i++) {
                var selection = selections;
                var row = selection.row;
                var rowCount = selection.rowCount;
                for (var r = row + rowCount - 1; r >= row; r--) {
                    operation(r);
                }
            }
        }
    }

  }
});

function getBaseApiUrl() {
    return window.location.href.match(/http.+spreadjs\/SpreadJSTutorial\//)[0] + 'server/api';
}

new Vue({
  render: (h) => h(App),
}).$mount("#app");
</script>











最佳答案

查看完整内容

经调研,在setDataView的时候,相关的table还没有fetch,因此会显示#N/A 把这部分代码 改成下面的代码即可

12 个回复

倒序浏览
最佳答案
最佳答案
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-3-5 16:34:07
来自 7#
oscartian 发表于 2022-3-7 14:13
辛苦版主了,希望能尽快解决

经调研,在setDataView的时候,相关的table还没有fetch,因此会显示#N/A

把这部分代码
  1. myTable.fetch().then(function() {
  2.             var view = myTable.addView("myView", [
  3.                 { value: "Id", width: 50, caption: "ID" },
  4.                 { value: "FirstName", width: 100, caption: "First Name" },

  5.                  { value: "customer", width: 150, style: multiSelectStyle},
  6.                 { value: "LastName", width: 100, caption: "Last Name" },
  7.                 { value: "HomePhone", width: 100, caption: "Phone" },
  8.                 { value: "Notes", width: 100, caption: "Notes" }
  9.             ]); //the View has all default columns of the Table
  10.             sheet.setDataView(view);
  11.         });
复制代码
改成下面的代码即可
  1. var view = myTable.addView("myView", [
  2.             { value: "Id", width: 50, caption: "ID" },
  3.             { value: "FirstName", width: 100, caption: "First Name" },

  4.                 { value: "customer", width: 150, style: multiSelectStyle},
  5.             { value: "LastName", width: 100, caption: "Last Name" },
  6.             { value: "HomePhone", width: 100, caption: "Phone" },
  7.             { value: "Notes", width: 100, caption: "Notes" }
  8.         ]); //the View has all default columns of the Table
  9.         //bind a view to the table sheet
  10.         view.fetch().then(function() {
  11.             sheet.setDataView(view);
  12.         });
复制代码




回复 使用道具 举报
oscartian
注册会员   /  发表于:2022-3-5 20:20:29
2#
本帖最后由 oscartian 于 2022-3-6 23:55 编辑

希望能有一个好的解决办法,顶一下帖子
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-3-7 11:05:45
3#
你好,我这边初始化加载是正常的,出现#N/A很有可能是网络请求的问题导致初始化数据没有正确加载,换个网络环境或者清空缓存再试一下应该是正常的了。
image.png925828552.png
回复 使用道具 举报
oscartian
注册会员   /  发表于:2022-3-7 11:33:49
4#
Derrick.Jiao 发表于 2022-3-7 11:05
你好,我这边初始化加载是正常的,出现#N/A很有可能是网络请求的问题导致初始化数据没有正确加载,换个网络 ...

我修改了这个例子的代码 ,将批量同步,与关系视图结合在一起了,你必须得跑一下我贴的代码,才能发现
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-3-7 13:50:53
5#
oscartian 发表于 2022-3-7 11:33
我修改了这个例子的代码 ,将批量同步,与关系视图结合在一起了,你必须得跑一下我贴的代码,才能发现

了解了,这边问题已复现需要做进一步调研,此贴先改为保留处理,有进展会在本帖更新(SJS-12114)
回复 使用道具 举报
oscartian
注册会员   /  发表于:2022-3-7 14:13:23
6#
Derrick.Jiao 发表于 2022-3-7 13:50
了解了,这边问题已复现需要做进一步调研,此贴先改为保留处理,有进展会在本帖更新(SJS-12114)

辛苦版主了,希望能尽快解决
回复 使用道具 举报
oscartian
注册会员   /  发表于:2022-3-7 16:55:20
8#
Derrick.Jiao 发表于 2022-3-7 16:15
经调研,在setDataView的时候,相关的table还没有fetch,因此会显示#N/A

把这部分代码

根据版主提供的代码还是存在同样的问题
回复 使用道具 举报
Derrick.Jiao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
论坛元老   /  发表于:2022-3-7 18:20:05
9#
附件是我的操作步骤以及粘贴的代码
tablesheet.gif83385924.png

app.vue

7.36 KB, 下载次数: 46

回复 使用道具 举报
oscartian
注册会员   /  发表于:2022-3-7 19:05:55
10#
Derrick.Jiao 发表于 2022-3-7 18:20
附件是我的操作步骤以及粘贴的代码

辛苦版主,谢谢啦!我这边重新测试以后能正常显示了,谢谢啦,能说明一下view.fetch()与myTable.fetch()的区别吗?刚才我就是这个地方出现了问题,才导致后面测试又出现问题的。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部