15

How can you set the "tool tip" that appears when you hover your mouse over a jqGrid row/cell?

Currently the tool tip appears to just be the cell contents.

Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

6 Answers6

23

In general I agree with Justin, that jqGrid get you no direct way to set tooltip on the row, you can do this only on the cell basis. So you have to do this manually.

First of all you should set title:false property on all cells to have no tooltip for the cells. Then you have to set your custom tooltips of every row. You can do this for example inside of loadComplete event handle. The corresponding code can be about following:

loadComplete: function() {
    var ids = grid.jqGrid('getDataIDs');
    for (var i=0;i<ids.length;i++) {
        var id=ids[i];
        var rowData = grid.jqGrid('getRowData',id);
        $('#'+id,grid[0]).attr('title', rowData.Name + ' (' +
                                        rowData.Category + ', ' +
                                        rowData.Subcategory + ')');
    }
}

You can see the corresponding example you can see live here.

UPDATED: In more late versions of jqGrid there are much more effective way to set custom title. It's the usage of cellattr (see the answer for an example) or the usage of rowattr (see the answer). I recommend to use gridview: true option of jqGrid always. The usage of cellattr or rowattr together with gridview: true allows to create full grid body inclusive of all tooltips which one need in one modification of the page (the full HTML fragment of grid body inclusive of all tooltips will be assigned to innerHTML property). The usage of .attr in the loop follows at least to reflow which is expansive (see here). So the usage of cellattr and rowattr in combination with gridview: true allow to achieve the best performance.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I test on your demo, and the tooltip doesn't always show up. For example, hover on row #1, then #2, then #1. How can the code be improved to always show the tooltip? – Eugene Yarmash Mar 17 '11 at 16:43
  • @eugene y: In what browser you have the problem? In my tests I see tooltip always. – Oleg Mar 17 '11 at 16:54
  • It was Firefox 3.6.15 Will check some other browsers later. – Eugene Yarmash Mar 17 '11 at 16:59
  • @eugene y: I could seen effects of instability of tooltips in FF 4.0 RCm, but I see the same problem in any tooltips: the the standard jqGrid for example. I don't know th reason. Probably it is a **bug in Firefox**. Look at [this post](http://bugs.jquery.com/ticket/7435). – Oleg Mar 17 '11 at 18:13
  • Yeah, seems to be a bug in FF. Thanks for your help! – Eugene Yarmash Mar 17 '11 at 20:02
  • @eugene y: You are welcome! But I didn't really solved the problem. – Oleg Mar 17 '11 at 20:50
2

There is no jqGrid API for this. If you want to change the tooltip text you will have to write code to manually change the value of the cell's title element.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
2

I had a similar problem, where jQuery just WOULD NOT recognize a mouseover even though the class was set correctly. As a test I setup

$('.note).mouseover(function(){alert('hello')})

No results. Then I changed it to

$('.note').live('mouseover',function(){alert('hello')})

and it worked. It was all about loading order. Hope this helps.

axel22
  • 32,045
  • 9
  • 125
  • 137
EWPDesign
  • 91
  • 1
  • 2
1

To highlight and assign a tooltip to an entire row, using jqgrid 4.4 and IE 11, this works.

  1. turn off tooltip in all cells when defining the colModel, for example:

    colModel: [ { name: 'ColumnName', title: false },...

  2. assign a loadComplete method to the grid:

    loadComplete: function () {
    var rows = $(this).getDataIDs();
    
    for (var i = 0; i < rows.length; i++) {
        var row = $(this).getRowData(rows[i]);
        if (row.IsSomething == 'true') {
            this.rows[i + 1].className = this.rows[i + 1].className + ' ui-state-highlight';
            $(this.rows[i + 1]).attr('title', 'This tooltip will appear for the entire row');
        }
    }
    

    } }

Tom Regan
  • 3,580
  • 4
  • 42
  • 71
0

Use a custom formatter

        function myCellFormatter(cellvalue, options, rowObject) {           
                return '<span title="' + rowObject.name + rowObject.category +rowObject.subcategory +'">'+ cellvalue +'</span>';

        }

And then use this formatter in the col model

{index: 'name', name: 'name',formatter:myCellFormatter, label: 'Name'},
...
Supra
  • 1,612
  • 1
  • 18
  • 36
0

I would like to extend my answer for using bootstrap tooltip with jqGrid. Grid sets a tooltip by default which could be cleared using title:false for each column.

To select a particular td or cell we could create our own class/attribute using cellattr property as a function for any cell. For example:

cellattr: function(rowID,val,rawObject,cm,rdata) {
    return "class='tooltip-cell';" // could return 'n' number of attributes
}

Then finally, bootstrap function tooltip could be called on a single or a collection of cells/td:

$('#myGrid .tooltip-cell').tooltip({
            container:'body',
            placement: 'bottom',
            title: 'Click to edit',
            trigger: 'hover'
        });

container:body needs to be used to maintain the behavior of html tables.

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328