jqGrid - Unselect row on click
Asked Answered
E

2

7

How can I unselect a row on click? I tried this:

beforeSelectRow: function(rowid, e) {
    if ($(this).getGridParam('selrow') == rowid) {
        return false;
    } else {
        return true;
    }
}

But only selection works, if I click on a selected row it does nothing.

Epizootic answered 11/12, 2013 at 16:6 Comment(0)
P
13

Instead of return false try:

$("#myGrid").jqGrid("resetSelection");

So your code would be:

beforeSelectRow: function (rowid) {
    if ($(this).jqGrid("getGridParam", "selrow") === rowid) {
        $(this).jqGrid("resetSelection");
    } else {
        return true;
    }
}
Pithy answered 11/12, 2013 at 18:59 Comment(5)
+1 from me - absolut correct code. I just made minimal improvements directly in your code. I hope you agree with it.Stine
@Stine I completely agree! Thank you!Pithy
@Stine it's funny... I started with jQGrid almost 2 years ago and you've helped me through my small to large problems I've had.. and now, I'm able to help others out! Great work Oleg :-)Pithy
You are welcome! So is it! I started with my first web development project about 3.5 years ago. I was new in JavaScript, jQuery and jqGrid. I started to answer on questions of other people at the beginning mostly to keep in the mind better new knowledge which I get in a short time. After writing some answers I could implement some new features in jqGrid which I posted to trirand. I find personally writing of answers good training and I recommend you to do the same. It will help not only other, but it will help you a lot too.Stine
@Stine exactly! Helping others not only helps them with their problem, but also reinforces what I know and helps improve my knowledge!Pithy
P
1

Try this

    onSelectRow: function(id, rowid){
        if(id && id!==lastsel3){
            jQuery('#NAME_GRID').jqGrid('saveRow',lastsel3); 
            lastsel3=id;
        }           
    },  

please declare lastsel3 = null;

Percussive answered 19/12, 2013 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.