我有一个w2ui网格如下:
$('#myGrid').w2grid({
name : 'myGrid',
columns: [
{ field: 'fname', text: 'First Name', size: '30%' },
{ field: 'lname', text: 'Last Name', size: '30%' },
{ field: 'email', text: 'Email', size: '40%' },
{ field: 'sdate', text: 'Start Date', size: '120px' },
],
show: {
toolbar: true,
selectColumn: true
},
records: [
{ recid: 1, fname: 'John', lname: 'Doe', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 4, fname: 'Susan', lname: 'Ottie', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 5, fname: 'Kelly', lname: 'Silver', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 6, fname: 'Francis', lname: 'Gatos', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 7, fname: 'Mark', lname: 'Welldo', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 8, fname: 'Thomas', lname: 'Bahh', email: '[email protected]', sdate: '4/3/2012' },
{ recid: 9, fname: 'Sergei', lname: 'Rachmaninov', email: '[email protected]', sdate: '4/3/2012' }
],
searches: [
{ field:'fname', label:'fname', type:'text', operator:'contains' },
{ field:'lname', label:'lname', type:'text', operator:'contains' },
]
});
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/w2ui-2.0.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/w2ui-2.0.min.css" rel="stylesheet">
<div id='myGrid' style='height:500px'></div>
我遇到的问题是,当我搜索某些特定值时,之前选择的记录变为未选中状态:
(在此示例中,记录“Francis Gatos”在搜索“an”字符串时变为未选中状态)。
有没有办法在应用搜索条件后保留选择?
w2ui 源代码非常干净。您可以轻松找到网格元素的“搜索”功能。在库文件中查找这一行(我使用的是es6版本的库):
this.last.selection.indexes = []
注释掉或删除此行。据我测试,没有任何副作用。