Skip to content

Commit

Permalink
Added new option in colModel title. Default is true. If false the tit…
Browse files Browse the repository at this point in the history
…le is not displayed in the cell. Also with this is possible to define a custom formatter and put what you want value for the title. Also added grid options headertitles (default false) if enabled the titles are added to the column headers.
  • Loading branch information
tonytomov committed Mar 2, 2010
1 parent 26293f3 commit 140d848
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
51 changes: 29 additions & 22 deletions js/grid.base.js
Expand Up @@ -182,7 +182,8 @@ $.fn.jqGrid = function( pin ) {
remapColumns : [],
ajaxGridOptions :{},
direction : "ltr",
toppager: false
toppager: false,
headertitles: false
}, $.jgrid.defaults, pin || {});
var grid={
headers:[],
Expand Down Expand Up @@ -376,20 +377,20 @@ $.fn.jqGrid = function( pin ) {
if (isNaN(val)) { return defval ? defval : 0;}
else {return val;}
},
formatCol = function (pos, rowInd){
formatCol = function (pos, rowInd, tv){
var ral = ts.p.colModel[pos].align, result="style=\"", clas = ts.p.colModel[pos].classes;
if(ral) result += "text-align:"+ral+";";
if(ts.p.colModel[pos].hidden===true) result += "display:none;";
if(rowInd===0) {
result += "width: "+grid.headers[pos].width+"px;"
}
return result+"\"" + (clas !== undefined ? (" class=\""+clas+"\"") :"");
return result+"\"" + (clas !== undefined ? (" class=\""+clas+"\"") :"") + ((ts.p.colModel[pos].title && tv) ? (" title=\""+$.jgrid.stripHtml(tv)+"\"") :"");
},
addCell = function(rowId,cell,pos,irow, srvr) {
var v,prp;
v = formatter(rowId,cell,pos,srvr,'add');
prp = formatCol( pos,irow);
return "<td role=\"gridcell\" "+prp+" title=\""+$.jgrid.stripHtml(v)+"\">"+v+"</td>";
prp = formatCol( pos,irow, v);
return "<td role=\"gridcell\" "+prp+">"+v+"</td>";
},
formatter = function (rowId, cellval , colpos, rwdat, _act){
var cm = ts.p.colModel[colpos],v;
Expand All @@ -412,12 +413,12 @@ $.fn.jqGrid = function( pin ) {
},
addMulti = function(rowid,pos,irow){
var v = "<input type=\"checkbox\""+" id=\"jqg_"+rowid+"\" class=\"cbox\" name=\"jqg_"+rowid+"\"/>",
prp = formatCol(pos,irow);
prp = formatCol(pos,irow,'');
return "<td role='gridcell' "+prp+">"+v+"</td>";
},
addRowNum = function (pos,irow,pG,rN) {
var v = (parseInt(pG,10)-1)*parseInt(rN,10)+1+irow,
prp = formatCol(pos,irow);
prp = formatCol(pos,irow,'');
return "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">"+v+"</td>";
},
reader = function (datatype) {
Expand Down Expand Up @@ -1275,9 +1276,13 @@ $.fn.jqGrid = function( pin ) {
imgs = "<span class='s-ico' style='display:none'><span sort='asc' class='ui-grid-ico-sort ui-icon-asc"+iac+" ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-"+dir+"'></span>";
imgs += "<span sort='desc' class='ui-grid-ico-sort ui-icon-desc"+idc+" ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-"+dir+"'></span></span>";
for(i=0;i<this.p.colNames.length;i++){
thead += "<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'>";
var tooltip = ts.p.headertitles ? (" title=\""+$.jgrid.stripHtml(ts.p.colNames[i])+"\"") :"";
thead += "<th role='columnheader' class='ui-state-default ui-th-column ui-th-"+dir+"'"+ tooltip+">";
idn = ts.p.colModel[i].index || ts.p.colModel[i].name;
thead += "<div id='jqgh_"+ts.p.colModel[i].name+"' "+tdc+">"+ts.p.colNames[i];
if(!ts.p.colModel[i].width) ts.p.colModel[i].width = 150;
else ts.p.colModel[i].width = parseInt(ts.p.colModel[i].width,10);
if(typeof(ts.p.colModel[i].title) !== "boolean") ts.p.colModel[i].title = true;
if (idn == ts.p.sortname) {
ts.p.lastsort = i;
}
Expand Down Expand Up @@ -1316,7 +1321,6 @@ $.fn.jqGrid = function( pin ) {
});
}

$.each(ts.p.colModel, function(i){if(!this.width) {this.width=150;} this.width = parseInt(this.width,10);});
if(ts.p.autowidth===true) {
var pw = $(eg).innerWidth();
ts.p.width = pw > 0? pw: 'nw';
Expand Down Expand Up @@ -1354,7 +1358,7 @@ $.fn.jqGrid = function( pin ) {
if(ts.p.viewsortcols[0]) {$("div span.s-ico",this).show(); if(j==ts.p.lastsort){ $("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}}
else if( j == ts.p.lastsort) {$("div span.s-ico",this).show();$("div span.ui-icon-"+ts.p.sortorder,this).removeClass("ui-state-disabled");}
}
tfoot += "<td role='gridcell' "+formatCol(j,0)+">&#160;</td>";
tfoot += "<td role='gridcell' "+formatCol(j,0,'')+">&#160;</td>";
}).mousedown(function(e) {
if ($(e.target).closest("th>span.ui-jqgrid-resize").length != 1) return;
var ci = $.jgrid.getCellIndex(this);
Expand Down Expand Up @@ -1817,7 +1821,7 @@ $.jgrid.extend({
return success;
},
setRowData : function(rowid, data, cssp) {
var nm, success=false;
var nm, success=false, title;
this.each(function(){
var t = this, vl, ind, cp = typeof cssp;;
if(!t.grid) {return false;}
Expand All @@ -1828,10 +1832,11 @@ $.jgrid.extend({
nm = this.name;
if( data[nm] != undefined) {
vl = t.formatter( rowid, data[nm], i, data, 'edit');
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
$("td:eq("+i+") > span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+i+") > span:first",ind).html(vl).attr(title);
} else {
$("td:eq("+i+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+i+")",ind).html(vl).attr(title);
}
success = true;
}
Expand Down Expand Up @@ -1880,12 +1885,12 @@ $.jgrid.extend({
var cna = t.p.altRows === true ? (t.rows.length-1)%2 == 0 ? cn : "" : "";
}
if(ni){
prp = t.formatCol(ni,1);
prp = t.formatCol(ni,1,'');
row += "<td role=\"gridcell\" class=\"ui-state-default jqgrid-rownum\" "+prp+">0</td>";
}
if(gi) {
v = "<input type=\"checkbox\""+" id=\"jqg_"+rowid+"\" class=\"cbox\"/>";
prp = t.formatCol(ni,1);
prp = t.formatCol(ni,1,'');
row += "<td role=\"gridcell\" "+prp+">"+v+"</td>";
}
if(si) {
Expand All @@ -1894,8 +1899,8 @@ $.jgrid.extend({
for(i = gi+si+ni; i < this.p.colModel.length;i++){
nm = this.p.colModel[i].name;
v = t.formatter( rowid, data[nm], i, data, 'add');
prp = t.formatCol(i,1);
row += "<td role=\"gridcell\" "+prp+" title=\""+$.jgrid.stripHtml(v)+"\">"+v+"</td>";
prp = t.formatCol(i,1,v);
row += "<td role=\"gridcell\" "+prp+">"+v+"</td>";
}
row = "<tr id=\""+rowid+"\" role=\"row\" class=\"ui-widget-content jqgrow ui-row-"+t.p.direction+" "+cna+"\">" + row+"</tr>";
if(t.p.subGrid===true) {
Expand Down Expand Up @@ -1948,7 +1953,7 @@ $.jgrid.extend({
return success;
},
footerData : function(action,data, format) {
var nm, success=false, res={};
var nm, success=false, res={}, title;
function isEmpty(obj) { for(var i in obj) { return false; } return true; }
if(typeof(action) == "undefined") action = "get";
if(typeof(format) != "boolean") format = true;
Expand All @@ -1963,7 +1968,8 @@ $.jgrid.extend({
if(action == "set") {
if( data[nm] != undefined) {
vl = format ? t.formatter( "", data[nm], i, data, 'edit') : data[nm];
$("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr("title",$.jgrid.stripHtml(vl));
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
$("tr.footrow td:eq("+i+")",t.grid.sDiv).html(vl).attr(title);
success = true;
}
} else if(action == "get") {
Expand Down Expand Up @@ -2183,7 +2189,7 @@ $.jgrid.extend({
},
setCell : function(rowid,colname,nData,cssp,attrp) {
return this.each(function(){
var $t = this, pos =-1,v;
var $t = this, pos =-1,v, title;
if(!$t.grid) {return;}
if(isNaN(colname)) {
$($t.p.colModel).each(function(i){
Expand All @@ -2198,10 +2204,11 @@ $.jgrid.extend({
var tcell = $("td:eq("+pos+")",ind);
if(nData !== "") {
v = $t.formatter(rowid, nData, pos,ind,'edit');
title = $t.p.colModel[pos].title ? {"title":$.jgrid.stripHtml(v)} : {};
if($t.p.treeGrid && $(".tree-wrap",$(tcell)).length>0)
$("span",$(tcell)).html(v).attr("title",$.jgrid.stripHtml(v));
$("span",$(tcell)).html(v).attr(title);
else
$(tcell).html(v).attr("title",$.jgrid.stripHtml(v));
$(tcell).html(v).attr(title);
}
if(typeof cssp === 'string'){
if(cssp) {$(tcell).addClass(cssp);}
Expand Down
12 changes: 7 additions & 5 deletions js/grid.custom.js
Expand Up @@ -122,7 +122,7 @@ $.jgrid.extend({
});
},
updateGridRows : function (data, rowidname, jsonreader) {
var nm, success=false;
var nm, success=false, title;
this.each(function(){
var t = this, vl, ind, srow, sid;
if(!t.grid) {return false;}
Expand All @@ -138,10 +138,11 @@ $.jgrid.extend({
if(t.p.jsonReader.cell) {srow = srow[t.p.jsonReader.cell];}
for (var k=0;k<srow.length;k++) {
vl = t.formatter( sid, srow[k], k, srow, 'edit');
title = t.p.colModel[k].title ? {"title":$.jgrid.stripHtml(vl)} : {};
if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
$("td:eq("+k+") > span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+k+") > span:first",ind).html(vl).attr(title);
} else {
$("td:eq("+k+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+k+")",ind).html(vl).attr(title);
}
}
success = true;
Expand All @@ -152,10 +153,11 @@ $.jgrid.extend({
nm = jsonreader===true ? this.jsonmap || this.name :this.name;
if( srow[nm] != undefined) {
vl = t.formatter( sid, srow[nm], i, srow, 'edit');
title = this.title ? {"title":$.jgrid.stripHtml(vl)} : {};
if(t.p.treeGrid===true && nm == t.p.ExpandColumn) {
$("td:eq("+i+") > span:first",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+i+") > span:first",ind).html(vl).attr(title);
} else {
$("td:eq("+i+")",ind).html(vl).attr("title",$.jgrid.stripHtml(vl));
$("td:eq("+i+")",ind).html(vl).attr(title);
}
success = true;
}
Expand Down

0 comments on commit 140d848

Please sign in to comment.