我使用格式化程序在网格单元格中放置了一个文本框小部件。但是,我无法移动光标,也无法在文本框中选择文本。
例如 http://jsfiddle.net/g33m9/69/
有谁知道如何解决这一问题?
谢谢
我使用格式化程序在网格单元格中放置了一个文本框小部件。但是,我无法移动光标,也无法在文本框中选择文本。
例如 http://jsfiddle.net/g33m9/69/
有谁知道如何解决这一问题?
谢谢
您需要将列设置为“可编辑”,以便 Grid 组件知道如何处理按键事件。所以修改布局是为了
var layout = [[
{name: 'Column 1', field: 'col1'},
{name: 'Column 2', field: 'col2', width:'200px', formatter: func}
]];
var layout = [[
{name: 'Column 1', field: 'col1'},
{name: 'Column 2', field: 'col2', width:'200px', formatter: func, editable: true}
]];
编辑状态通过双击激活。
现在,OP 希望它成为一个完全臃肿的小部件,以可编辑状态弹出。为了使它可以使用任意数量的行/列进行扩展,我将其限制为编辑状态,以便该值仅显示文本,但一旦双击它将弹出一个 FilteringSelect。dijit 小部件 ValidationTextBox 的原理相同。
当前(1.7.2)可能的单元格类型是:dojox.grid.cells.Bool dojox.grid.cells.ComboBox dojox.grid.cells.DateTextBox dojox.grid.cells.Select
抓住我的SEO:
var i = 0,
data = {
identifier: 'id',
items: [
{ id: i, value: 'val'+i++},
{ id: i, value: 'val'+i++},
{ id: i, value: 'val'+i++},
{ id: i, value: 'val'+i++}
]
},
// The item label which holds visible value and which holds the value to represent
searchAttr = 'value',
valueAttr = data.identifier,
// The store to use for select widget
store = new dojo.data.ItemFileReadStore({ data: data }),
// And the options, reassembling the valid options we will present in dropdown
// Used when cellType is dojox.grid.cells.Select to name the allowable options
options = [];
dojo.forEach(data.items, function(it) { options.push(it[searchAttr])});
让我们扩展现有的dojox.grid.cells.Cell
,它有两个关键特性 - 编辑状态格式化程序和默认格式化程序。默认设置就可以了。最后但同样重要的是,我们将覆盖“_finish”函数,尽管允许 Cell 也处理它自己的定义。
var whenIdle = function( /*inContext, inMethod, args ...*/ ) {
setTimeout(dojo.hitch.apply(dojo, arguments), 0);
};
var FilteringSelectCell = declare("dojox.grid.cells.FilteringSelect", [dojox.grid.cells.Cell], {
options: null,
values: null,
_destroyOnRemove: true,
constructor: function(inCell){
this.values = this.values || this.options;
},
selectMarkupFactory: function(cellData, rowIndex) {
var h = ['<select data-dojo-type="dijit.form.FilteringSelect" id="deleteme' + rowIndex + '" name="foo">'];
for (var i = 0, o, v;
((o = this.options[i]) !== undefined) && ((v = this.values[i]) !== undefined); i++) {
v = v.replace ? v.replace(/&/g, '&').replace(/</g, '<') : v;
o = o.replace ? o.replace(/&/g, '&').replace(/</g, '<') : o;
h.push("<option", (cellData == v ? ' selected' : ''), ' value="' + v + '"', ">", o, "</option>");
}
h.push('</select>');
return h;
},
textMarkupFactory: function(cellData, rowIndex) {
return ['<input class="dojoxGridInput" id="deleteme' + rowIndex + '" data-dojo-type="dijit.form.ValidationTextBox" type="text" value="' + cellData + '">']
},
// @override
formatEditing: function(cellData, rowIndex) {
this.needFormatNode(cellData, rowIndex);
var h = (cellData == "W1")
? this.textMarkupFactory(cellData, rowIndex)
: this.selectMarkupFactory(cellData, rowIndex);
// a slight hack here, i had no time to figure out when the html would actually be inserted to the '<td>' so.. Use 'debugger' statement and track function to hook into
whenIdle(function() {
dojo.parser.parse(dojo.byId('deleteme' + rowIndex).parentNode);
var w = dijit.byId('deleteme' + rowIndex);
w.focus()
});
return h.join('');
},
// clean up avoiding multiple widget definitions 'hanging'
_finish: function(inRowIndex) {
this.inherited(arguments)
dijit.byId('deleteme' + inRowIndex).destroy();
},
// needed to read the value properly, will work with either variant
getValue: function(rowIndex) {
var n = this.getEditNode(rowIndex);
n = dijit.getEnclosingWidget(n);
return n.get("value");
}
});
var layout = [[
{ name: 'Column 1', field: 'col1' },
{ name: 'Column 2', field: 'col2',
cellType: FilteringSelectCell, options: options, editable: true
}
]];
在此处运行示例 http://jsfiddle.net/dgbxw/1/