我有一个启用了多重选择的 w2ui 网格。 我的目标是禁用某些行的选择并保留其他行的可用选择。
let grid = new w2grid({
name: 'grid',
box: '#grid',
multiSelect: true,
show: {
selectColumn: true
},
columns: [
{ field: 'recid', text: 'recid', size: '10px', sortable: true, attr: 'align="center"' },
{ field: 'field', text: 'field', size: '500px', sortable: true },
],
records: [
{ recid: 1, field: 'You cannot select this' },
{ recid: 2, field: 'neither this' },
{ recid: 3, field: 'but you can select this' },
{ recid: 4, field: 'or this' },
{ recid: 5, field: 'and what do you think about this?' },
{ recid: 6, field: 'Ok no, not this one' },
{ recid: 7, field: 'as even this must be disabled' },
]
})
<link href="https://cdn.jsdelivr.net/npm/[email protected]/w2ui-2.0.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/w2ui-2.0.min.js"></script>
<div id='grid' style='height:500px'></grid>
是否可以只允许对某些记录进行记录选择?
使用方法 event.preventDefault() onSelect 事件:
onSelect(event) {
if ( disable.selection == true ) event.preventDefault()
}