Disable single row selection function of w2ui grid
P粉148782096
P粉148782096 2023-09-16 14:42:53
0
1
1272

I have a w2ui grid with multiSelect enabled. My goal is to disable selection of certain rows and keep other rows selectable.

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: '你不能选择这个' },
        { recid: 2, field: '也不能选择这个' },
        { recid: 3, field: '但你可以选择这个' },
        { recid: 4, field: '或者这个' },
        { recid: 5, field: '你觉得这个怎么样?' },
        { recid: 6, field: '好吧,不是这个' },
        { recid: 7, field: '甚至这个也必须被禁用' },
    ]
})
<link href="https://cdn.jsdelivr.net/npm/w2ui@2.0.0/w2ui-2.0.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/w2ui@2.0.0/w2ui-2.0.min.js"></script>
<div id='grid' style='height:500px'></grid>

Is it possible to only allow certain records to be selected?

P粉148782096
P粉148782096

reply all(1)
P粉810050669

Use method event.preventDefault() in onSelect event:

onSelect(event) {
                if ( disable.selection == true ) event.preventDefault()
            }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template