思路:
通过重写 GC.Spread.Sheets.CellRange.prototype.bindingPath 来修改绑定字段逻辑。
核心代码:
- var oldSetBindingPath = GC.Spread.Sheets.CellRange.prototype.bindingPath;
- GC.Spread.Sheets.CellRange.prototype.bindingPath = function(a) {
- var sheet = this.sheet;
- var rc = sheet.getRowCount();
- var cc = sheet.getColumnCount();
- // 遍历单元格,查看是否该字段已设置。如果是,则弹出弹窗提示,并取消绑定该字段
- for(var r = 0; r < rc; r++) {
- for(var c = 0; c < cc; c++) {
- var path = sheet.getBindingPath(r, c);
- if(path == a) {
- alert("该字段已绑定!请勿拖拽");
- return;
- }
- }
- }
- oldSetBindingPath.call(this, a)
- }
复制代码 完整代码请查看附件demo。
|
|