Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change cursor style depending on sort or not

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

like image 511
Mark P. Avatar asked Apr 12 '11 18:04

Mark P.


People also ask

What is the difference between mouse pointer and cursor?

In computer user interfaces, a cursor is an indicator used to show the current position for user interaction on a computer monitor or other display device that will respond to input from a text input or pointing device. The mouse cursor is also called a pointer, owing to its resemblance in usage to a pointing stick.

What is the default cursor CSS?

If the value of the cursor property is set to default, generally the cursor will look like an arrow, which is the default cursor display.

How do I change my cursor to a straight line?

In the Pointers tab of the Mouse Properties pop up, select on the cursor you want to change under Customize and then click on "Browse" on the bottom-right hand corner of the screen. 2. You will now see a slew of cursor options for you to choose from. Select the cursor that you want and Click Open.


2 Answers

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"});
    }
});

You can see on the demo live that the method work. In the demo the last column 'Notes' is non-sortable.

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.

like image 183
Oleg Avatar answered Oct 01 '22 08:10

Oleg


Welcome to SO.

Absolutely. CSS:

th.unsortableclass {
cursor: default;
}

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

like image 23
Adam Terlson Avatar answered Oct 01 '22 09:10

Adam Terlson