我希望能够扩展一行并显示可编辑的div并能够编辑它。然而,当我将文本光标放在可编辑的div中时,它几乎立即失去焦点 有没有办法阻止div失去焦点?
我已经制作了一个jsFiddle来演示这个问题:http://jsfiddle.net/h2zoqm0n/1/
示例代码:
$(function () {
$('#grid').w2grid({
name: 'grid',
header: 'List of Names',
records: [
{ "recid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 2, "fname": "Stuart", "lname": "Motzart", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 3, "fname": "Jin", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 4, "fname": "Susan", "lname": "Ottie", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 5, "fname": "Kelly", "lname": "Silver", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 6, "fname": "Francis", "lname": "Gatos", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 7, "fname": "Mark", "lname": "Welldo", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 8, "fname": "Thomas", "lname": "Bahh", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 9, "fname": "Sergei", "lname": "Rachmaninov", "email": "jdoe@gmail.com", "sdate": "4/3/2012" }
],
method: 'GET', // need this to avoid 412 error on Safari
show: {
header : true,
toolbar : true,
footer : true,
lineNumbers : true,
selectColumn: true,
expandColumn: true
},
columns: [
{ field: 'fname', caption: 'First Name', size: '30%' },
{ field: 'lname', caption: 'Last Name', size: '30%' },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'sdate', caption: 'Start Date', size: '120px' }
],
searches: [
{ type: 'int', field: 'recid', caption: 'ID' },
{ type: 'text', field: 'fname', caption: 'First Name' },
{ type: 'text', field: 'lname', caption: 'Last Name' },
{ type: 'date', field: 'sdate', caption: 'Start Date' }
],
onExpand: function (event) {
var data = w2ui.grid.get(event.recid);
var cmp1 = data.fname;
var cmp2 = data.lname;
$('#' + event.box_id).html('<div style=""><table style="width: 100%;"><tr><td>' + cmp1 + '</td><td><div id="d" style="white-space: nowrap; border: 1px solid black;" contenteditable="true">' + cmp2 + '</div></td></tr></table ></div>');
}
});
});
...还有一个带有id&#34; grid&#34;:
的div<div id="grid" style="width: 100%; height: 400px; overflow: hidden;"></div>
答案 0 :(得分:1)
在div中使用带 自动对焦属性 的输入元素进行编辑cmp2值
onExpand函数的示例
onExpand: function (event) {
var data = w2ui.grid.get(event.recid);
var cmp1 = data.fname;
var cmp2 = data.lname.replace("\n", "<br>");
$('#' + event.box_id).html('<div style=""><table style="width: 100%;"><tr><td>' + cmp1 + '</td><td><div id="DataInExcelEdit" style="white-space: nowrap; border: 1px solid black;" contenteditable="true"> <input style="width:100%" autofocus value=' + cmp2 + ' /></div></td></tr></table ></div>');
}
以及更多 我认为你应该在单元格中进行编辑而不是在扩展列时,这不是look at that
的有效方法