Is it possible to Stop jqGrid row(s) from being se

2020-05-25 17:37发布

I've looked at the documentation but I've been unable to find an answer. Is there a way to prevent a row from being highlighted when selected? That or even a way to stop the row being selected at all. I like the "hoverrows: true" option, but ideally I would like to stop a row from being selected on-click.

Thanks,

Update: I've been able to "hackily" implement something which seems to be an interim fix. I don't really like it at all and would idealy like a better solution, if there is one...

I have found that if I pass the option

onSelectRow: function(rowid, status) {
    $('#'+rowid).removeClass('ui-state-highlight');
}

when I instantiate the jqGrid, I can strip the highlight when it is added.

Is there another, more ideal, way to do this?

5条回答
再贱就再见
2楼-- · 2020-05-25 18:00

Yes, use the rowattr callback:

rowattr: function (rowData,currentObj,rowId) {
    if (rowData.SomeField=="SomeValue") { 
        return {"class": "ui-state-disabled"};
    }
},

This also grays out the row and disables the selection.

查看更多
祖国的老花朵
3楼-- · 2020-05-25 18:02

If you, like me, have a gazillion jqGrids and don't want to override onSelectRow for every single one, here's a global version of Reigel's solution that worked nicely for me:

jQuery.extend(jQuery.jgrid.defaults, {
    onSelectRow: function(rowid, e) {
        $('#'+rowid).parents('table').resetSelection();
    }
});
查看更多
爷的心禁止访问
4楼-- · 2020-05-25 18:04

Use the following code:

beforeSelectRow: function(rowid, e) {
    return false;
}
查看更多
▲ chillily
5楼-- · 2020-05-25 18:12

I suppose you could address this in the CSS directly. Just override the values for ui-state-highlight for your specific table

#table_id tr.ui-state-highlight {
  border: inherit !important;
  background: inherit !important;
  color: inherit !important;
}

#table_id tr.ui-state-highlight a {
  color: inherit !important;
}

#table_id tr.ui-state-highlight .ui-icon {
  background-image: inherit !important;
}

I used the value inherit just as an example - you will likely need to copy some values from your theme.css to make this work.

查看更多
Lonely孤独者°
6楼-- · 2020-05-25 18:13

try:

onSelectRow: function(rowid, status) {
    $("#grid_id").resetSelection(); //Resets (unselects) the selected row(s). Also works in multiselect mode.
}

you can read documentations here. Hope it helps you...

查看更多
登录 后发表回答