与其即时选择编辑器,不如将相似的数据分组到同一列中以便可以使用相同的编辑器?
var columns = [{
editor: new Y.TextAreaCellEditor(),
key: 'name'
}, {
editor: new Y.DateCellEditor({
dateFormat: '%m/%d/%Y'
}),
key: 'birthday'
}];
如果您像这样对数据进行分组,那么您可以editEvent
将 dataTable更改为dblclick
:
var dataTable = new Y.DataTable({
// ...
editEvent: 'dblclick'
}).render('#dataTable');
这是一个工作示例:
YUI().use('aui-datatable', function(Y) {
var columns = [{
editor: new Y.TextAreaCellEditor(),
key: 'name'
}, {
editor: new Y.DateCellEditor({
dateFormat: '%m/%d/%Y'
}),
key: 'birthday'
}];
var data = [{
birthday: '9/9/1999',
name: 'Jonathan Smithy'
}, {
birthday: '10/10/1990',
name: 'Bob Duncan'
}];
var dataTable = new Y.DataTable({
columnset: columns,
recordset: data,
editEvent: 'dblclick'
}).render('#dataTable');
});
<script src="https://cdn.rawgit.com/stiemannkj1/701826667a70997013605edcd37e92a6/raw/469fe1ae297e72a5a80eb9015003b7b04eac735e/alloy-ui-3.0.1_aui_aui-min.js"></script>
<link href="https://cdn.rawgit.com/stiemannkj1/90be22de7f48c729b443af14796d91d3/raw/a9f35ceedfac7fc0559b121bed105eaf80f10bf2/aui-css_css_bootstrap.min.css" rel="stylesheet"></link>
<div id="dataTable"></div>
如果您必须动态选择和显示编辑器,我建议您看一下getEditor(record, column)
. A.DataTable.CellEditorSupport
我无法getEditor()
上班,但我认为如果你能让它正常工作,你可以做类似getEditor(data[1], column[0]).show()
.