13

I'm using the jqGrid and have 3 columns that can NOT be sorted. At this point the cursor changes to a hand when the user hovers over the headers regardless of sorting set to true or false. I'd like that cursor to be something other than a hand (text or pointer) on those column heads. It's confusing to the users this way. Is this something that can be set?

Thanks, Mark

Mark P.
  • 282
  • 1
  • 4
  • 16

4 Answers4

17

I find the question very good. So +1 from me.

You are not the first person (and not the last one) who wish to have another cursor on non-sortable columns. It's pity, but jqGrid gives you not classes or some other simple attributes which can be used to find the elements at which one can set CSS "cursor:default".

So I suggest to do this with the following code:

var myGrid = $("#list");

// create the grid
myGrid.jqGrid({
  // all jqGrid parameters
});

// fix cursor on non-sortable columns
var cm = myGrid[0].p.colModel;
$.each(myGrid[0].grid.headers, function(index, value) {
    var cmi = cm[index], colName = cmi.name;
    if(!cmi.sortable && colName!=='rn' && colName!=='cb' && colName!=='subgrid') {
        $('div.ui-jqgrid-sortable',value.el).css({cursor:"default"});
    }
});

It would be nice if such behavior would be standard in the next version of jqGrid. I will try to find time and to write suggestion what from the code of jqGrid should be changed to make the behavior out-of-the-box.

UPDATED: The problem with the cursor on non-sortable columns is not exist more in free jqGrid 4.8.

Avatar
  • 14,622
  • 9
  • 119
  • 198
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I take it you can't just add `cursor:default` to the colModel? (I know nothing of jqGrid--Just wondering) – Adam Terlson Apr 12 '11 at 19:40
  • @Adam Terlson: To which properties in the `colModel` you can add "cursor:default" (see [here](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options))? There are no one which will apply to the column header. The "classes" attribute will apply to `` and not `` element. You can not easy redefine the CSS for any `` of grid, because you want to set "cursor:default" **only to not-sortable** columns. So I see no very simple way to do this, but what I suggested are just some lines of code and it works. – Oleg Apr 12 '11 at 19:45
  • Thank you very much Oleg, it worked wonderfully. And thanks to the rest for quick replies. – Mark P. Apr 12 '11 at 19:51
  • Why is that little tutorial directed at me? It wasn't even my question you're answering.... If you're trying to say that I should upvote your answer, I didn't even test it--so why would I upvote what I don't know works? – Adam Terlson Apr 12 '11 at 19:56
  • @Mark Pusateri: Voting is just clicking the upward pointing arrow to the left of the answer. Voting is very important on the stackoverflow because of many things. 1) It will be used in **sorting and searching engine** (even by Google). The answer which are not voted up will be interpret as **not helpful** and will be not found in many cases. 2) Voting up is the form to say "thanks" to the answer. The user having higher reputation helped many people and you can more "trust" his statements. I recommend you to read [FAQs](http://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites). – Oleg Apr 12 '11 at 20:06
  • @Mark Pusateri: Just read in you question "why would I upvote what I don't know works?". It is correct, but sometime you receive new idea from an answer: to use come CSS which you don't know, a link to some interesting resource and so on. So you should vote up **not all answers**, but only the answers which helped you. Only this would help other to find the same information. For example you will probably not find [the answer](http://stackoverflow.com/questions/3462071/jqgrid-get-th-and-thead-using-jquery/3463002#3463002), but it could be helpful for you and other. You can understand why. – Oleg Apr 12 '11 at 20:24
  • Well, it didn't help me, nor did I really learn anything that's relevant to the question. Don't pander for votes when you don't get them. – Adam Terlson Apr 13 '11 at 16:58
  • Why do you exclude columns named 'rn', 'cb', and 'subgrid'? Are they special? – Luke Dec 13 '16 at 14:53
  • @Luke: The `colModel` can be modified by jqGrid if some additional options are used. The option `rownumbers: true` follow inserting the column `rn`, the option `multiselect: true` instead `cb` column (if `multiselectPosition: "none"` is not specified additionally), the option `subGrid: true` follows inserting `subgrid` column. – Oleg Dec 13 '16 at 15:23
1

Welcome to SO.

Absolutely. CSS:

th.unsortableclass {
cursor: default;
}

Now apply that class to your column headers that aren't sortable.

Adam Terlson
  • 12,610
  • 4
  • 42
  • 63
  • OK.. I'm pretty sure I'm doing it wrong. Here's what I have: $("#list").jqGrid('setLabel', 5, 'Description', {'cursor':'pointer'}); And it doesn't work. If I change 'Description' it changes, if I change the style to text based, it changes. So I'm assuming the setLabel isn't correct. Hints? – Mark P. Apr 12 '11 at 19:06
  • I'm not familiar with jqGrid, but you'll just need to look at the params for that call. Here's a page: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:conventions Check out the column formatting stuff. Looks like you could put cursor: default in there. – Adam Terlson Apr 12 '11 at 19:37
1

Oleg's example worked great but I had a request to always show the arrows if the column was sortable. I know I'm commenting but thought some one might have the same requirement.

So I added this to his loop:

jQuery('span.s-ico',value.el).remove();

Then after his code runs:

jQuery(".s-ico").show();

And then added this to my grid create:

onSortCol:function(index, iCol, sortorder){
    // redisplay all arrows
    jQuery(".s-ico").show();
}
Jack
  • 11
  • 1
-1
$("jquery selector to pick only non-sorted columns").css("cursor", "default");
j0k
  • 22,600
  • 28
  • 79
  • 90
Thebigcheeze
  • 3,408
  • 2
  • 22
  • 18