Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqgrid single select checkbox

In Jqgrid, I want to restrict user to 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

like image 810
Sabarish Avatar asked Jul 20 '11 01:07

Sabarish


4 Answers

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.

like image 107
LeftyX Avatar answered Nov 03 '22 05:11

LeftyX


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;
        }
like image 26
Leandro Carvalho Avatar answered Nov 03 '22 05:11

Leandro Carvalho


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?

like image 2
Justin Ethier Avatar answered Nov 03 '22 03:11

Justin Ethier


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.

like image 2
De Shan Baptiste Avatar answered Nov 03 '22 05:11

De Shan Baptiste