简体   繁体   中英

multiselect behavior in single select jqGrid

I have a page with a jqGrid in it. Is has to be multiselect:false because I have to allow only one row to be selected, but I also need to select multiple rows (ie I want to have many rows marked but only one active). So I've created a grid whith multiselect:false and a checkbox row with formatter: 'checkbox' I've also created a master checkbox in the collumn header (the 'name' of the collumn in the colNames is <input id="cbSelectAll" type="checkbox"> )

To change all the rows at once when the header is clicked I've created the function:

        $('#cbSelectAll').click(function (e) {
            var valor = $(this).is(':checked');
                $.each($('#grid input[type="checkbox"]'), function (idx, elm) {
                    var id = $(elm).closest('tr').attr('id');
                    var cb = $('#' + id + ' td').children().first();
                    $(cb).attr('checked', valor);
                    selectedRows[id] = valor;
                });
            /* other non relevant code */
        });

Now that's my problem. This function works nicelly when I try to unselect the checkbox's but when i try to select then it only works in the first time. On the subsequent clicks the checked attribute is changed but the box is not visually changed.

Instead of attr, try using prop

Please have a look at this similar issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM