When the mouse hovers over each column I'd like the tooltip to indicate whether that column is sortable.
I am able to change the title attribute with something like this:$("#List .ui-th-column").each(function(i) {
var isSortable = i % 2;
$(this).attr('title', isSortable ? "Not Sortable" : "Click header to sort.");
});
I'd like to replace the demo expression 'i % 2' with a check of the colMode's sortable property, but I can't figure out how to get the value of the colModel's sortable property.
colModel: [ { name: 'Name', index: 'Name', width: 100, sortable: true },
{ name: 'Note', index: 'Note', width: 200, sortable: false } ]
I've tried .getGridParam and .getColProp but I don't think the syntax I'm using 开发者_高级运维is correct.
To get the value of the sortable
property like any other property from the column definition you can do about following:
var grid=$("#list");
var propsName = grid.jqGrid('getColProp','Name');
var propsNote = grid.jqGrid('getColProp','Note');
alert("'Name' has sortable="+propsName.sortable+
"\n'Note' has sortable="+propsNote.sortable);
To set tooltip on the column header you can do following
var setTooltipsOnColumnHeader = function (grid, iColumn, text) {
var thd = $("thead:first", grid.hdiv)[0];
$("tr th:eq(" + iColumn + ")", thd).attr("title", text);
};
var grid=$("#list");
setTooltipsOnColumnHeader(grid,2,"Bla Bla!");
Here we identify the column by index of visible columns.
You can easy rewrite the code examples for your purpose.
This works nicely. thanks for all the help Oleg.
$("#gbox_List .ui-th-column").each(function(i) {
var col = grid.getGridParam('colModel');
var isSortable = grid.jqGrid("getColProp", col[i].name).sortable;
$(this).attr('title', isSortable ? "Click header to sort by column." : "Not Sortable");
});
You were right about the $(#List not being in the correct place on the DOM, it should have been #gbox_List - the additional info made that clear.
I had to use .ui-th-column rather than .ui-th-labels for the .each to loop through each column.
I was able to avoid hard coding the column name by using the grid.getGridParam('colModel') to return an array and then grabbing the .name property off of that for each column.
This solution is nice because I have ~20 grids, each with lots of unsortable columns and having to have a different line for each unsortable column would have been messy. Now I can take advantage of the sortable property setting in the colModel.
精彩评论