我正在使用w2ui
(http://w2ui.com/)插件。
考虑以下示例:1
我想要单击添加按钮时在网格中显示一个空的可编辑行以添加新行吗?
我没有找到隐藏搜索框的配置,该如何隐藏呢?
如何将列设置为ID?目前,它只能识别recid
。
最佳答案
以下是单击按钮时如何在网格中添加新记录的示例:
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="../css/w2ui.css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/w2ui.js"></script>
<script>
$(function () {
$('#grid').w2grid({
name: 'grid',
show: {
toolbar: true,
footer: true,
header: true,
columnHeaders: true,
lineNumbers: true,
toolbarDelete: true,
toolbarSave: true,
toolbarAdd: true
},
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, resizable: true, searchable: 'int' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true, resizable: true, searchable: true,
editable: { type: 'text' }
},
{ field: 'fname', caption: 'First Name', size: '30%', sortable: true, resizable: true, searchable: true,
editable: { type: 'text' }
},
],
onAdd: function (target, data) {
var recid = 1;
if (this.records.length > 0) recid = (Math.max.apply(Math, this.find({}))) + 1;
this.add({ recid: recid });
$('#grid_grid_edit_'+ (this.records.length - 1) +'_1').focus();
},
onSave: function (target, data) {
var obj = this;
console.log(data);
data.onComplete = function () {
for (var r in data.changed) {
obj.get(data.changed[r].recid).editable = false;
}
obj.refresh();
}
}
});
});
</script>
</head>
<body>
<div id="grid" style="width: 100%; height: 500px;"></div>
</body>
</html>