开发者

jqgrid single select checkbox

In Jqgrid, I want to restrict user to开发者_如何学Go select only one check box at any time. When user selects multiple check box only last selected to be in 'selected' state, remaining should be automatically un-selected.

I have set multi select attribute to true. But I am not able to do un-select previously selected item. Is it possible to do if so how?

Thanks


You can use the event beforeSelectRow and reset the selection:

beforeSelectRow: function(rowid, e)
{
    jQuery("#list47").jqGrid('resetSelection');
    return(true);
}

I've got a fiddle for you so you can check how it works.


You have to do some more stuff:

1. Set multiboxonly to true and multiselect to true

2. Define the events onSelectRow and beforeSelectRow:

3. Define global variable: var lastSel;


The OnSelectRow and beforeSelectRow implementation:

onSelectRow: function (rowId, status, e) {
        if (rowId == lastSel) {
            $(this).jqGrid("resetSelection");
            lastSel = undefined;
            status = false;
        } else {
            lastSel = rowId;
        }
    },
beforeSelectRow: function (rowId, e) {
            $(this).jqGrid("resetSelection");
            return true;
        }


Having a checkbox in each column implies that you can click more than one at a time. What you are asking for is basically the multiselect: false behavior but with the checkbox column - are you sure you really want the checkboxes in this case?


I know this question is old, but I found a better solution in this Stack Post.

All you have to do is set the following two properties of the jqGrid:

multiselect:true // multi-select checkboxes appear

multiboxonly:true // checkboxes act like radio buttons where only one is selected at a time

I have updated the fiddle made by LeftyX to simply use the multiboxonly setting at this JsFiddle

This was what I needed. It may help someone else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜