max*_*mus 1 javascript jquery jquery-plugins slickgrid
我想用SlickGrid模仿电子表格的特定行为.用户:
=sum(,或任何公式,什么让我失望的是需要改变焦点.
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;
}
};
Run Code Online (Sandbox Code Playgroud)
提前致谢!
这在SlickGrid 1.4.x中是不可能的,但在目前仍处于活动开发的2.0版本中将得到支持.alpha存放在GitHub上的一个单独的分支中 - https://github.com/mleibman/SlickGrid/tree/v2.0a,我刚刚通过示例检查了支持此功能的初步代码.请参阅https://github.com/mleibman/SlickGrid/commit/17b1bb8f3c43022ee6aec89dcab185cd368b8785.
这是一个基本的公式编辑器实现:
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();
}