SlickGrid 类似 Excel 的行为

发布于 2024-10-03 05:55:30 字数 689 浏览 0 评论 0 原文

我想用 SlickGrid 模仿电子表格的特定行为。用户:

  1. 单击单元格以激活它
  2. 输入=sum(,或任何公式,
  3. 原始单元格地址被保存
  4. 用户选择单元格范围(我假设原始单元格关闭编辑器)
  5. 焦点返回到原始单元格并附加了新的单元格范围,即 =sum(r1c1,r2c2) ,

的是需要更改焦点。

var cell_with_formula = null;
grid = new Grid($("#myGrid"), data, columns, options);

// save original cell address, but there is no onBlur event
grid.onBlur = function(args){
  cell_with_formula = args; // save address
}; 

grid.onCellRangeSelected = function(){
  if(cell_with_formula){
    // check if cell_with_formula has `=` at begining
    // if so, append selected range    
    cell_with_formula = null;
  }
}; 

让我感到困惑

I'd like to mimic a particular behavior of spreadsheets with SlickGrid. The user:

  1. clicks on a cell to activate it
  2. enters =sum(, or whatever formula,
  3. the original cell address is saved
  4. the user selects the cell range (I assume that the original cell closes the editor)
  5. focus is returned to the original cell with the new cell range appended. i.e. =sum(r1c1,r2c2).

What's throwing me off is the need to change focus.

var cell_with_formula = null;
grid = new Grid($("#myGrid"), data, columns, options);

// save original cell address, but there is no onBlur event
grid.onBlur = function(args){
  cell_with_formula = args; // save address
}; 

grid.onCellRangeSelected = function(){
  if(cell_with_formula){
    // check if cell_with_formula has `=` at begining
    // if so, append selected range    
    cell_with_formula = null;
  }
}; 

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦一生花开无言 2024-10-10 05:55:30

这在 SlickGrid 1.4.x 中是不可能的,但在目前仍在积极开发的 2.0 版本中将得到支持。 alpha 托管在 GitHub 上的单独分支中 - https://github.com/mleibman/ SlickGrid/tree/v2.0a,我刚刚通过示例检查了支持此功能的初步代码。请参阅<

这是一个基本的公式编辑器实现:

function FormulaEditor(args) {
    var _self = this;
    var _editor = new TextCellEditor(args);
    var _selector;

    $.extend(this, _editor);

    function init() {
        // register a plugin to select a range and append it to the textbox
        // since events are fired in reverse order (most recently added are executed first),
        // this will override other plugins like moverows or selection model and will
        // not require the grid to not be in the edit mode
        _selector = new Slick.CellRangeSelector();
        _selector.onCellRangeSelected.subscribe(_self.handleCellRangeSelected);
        args.grid.registerPlugin(_selector);
    }

    this.destroy = function() {
        _selector.onCellRangeSelected.unsubscribe(_self.handleCellRangeSelected);
        grid.unregisterPlugin(_selector);
        _editor.destroy();
    };

    this.handleCellRangeSelected = function(e, args) {
        _editor.setValue(_editor.getValue() + args.range);
    };


    init();
}

This is not possible in SlickGrid 1.4.x, but is going to be supported in the version 2.0 that is currently still under active development. The alpha is hosted in a separate branch on GitHub - https://github.com/mleibman/SlickGrid/tree/v2.0a, and I just checked in preliminary code that supports this with an example. Please see https://github.com/mleibman/SlickGrid/commit/17b1bb8f3c43022ee6aec89dcab185cd368b8785.

Here's a basic formula editor implementation:

function FormulaEditor(args) {
    var _self = this;
    var _editor = new TextCellEditor(args);
    var _selector;

    $.extend(this, _editor);

    function init() {
        // register a plugin to select a range and append it to the textbox
        // since events are fired in reverse order (most recently added are executed first),
        // this will override other plugins like moverows or selection model and will
        // not require the grid to not be in the edit mode
        _selector = new Slick.CellRangeSelector();
        _selector.onCellRangeSelected.subscribe(_self.handleCellRangeSelected);
        args.grid.registerPlugin(_selector);
    }

    this.destroy = function() {
        _selector.onCellRangeSelected.unsubscribe(_self.handleCellRangeSelected);
        grid.unregisterPlugin(_selector);
        _editor.destroy();
    };

    this.handleCellRangeSelected = function(e, args) {
        _editor.setValue(_editor.getValue() + args.range);
    };


    init();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文