Forum
11:25
15/01/2009
Hi, Tony!
To solve my problem in jqGrid I had to be able to specify different styles for different cells. For example, draw a chess board 🙂
It would like to see such a possibility.
While a done like this.
Implemented only for JSON. Version jqGrid 3.4 beta.
The idea is to expand the data yet another array of styles for each cell. In my code, this array is called the "cssp".
--- grid.base.js.orig Sun Jan 11 14:33:42 2009
+++ grid.base.js Sun Jan 18 18:53:37 2009
@@ -570,7 +570,7 @@
if (cssp){
if(typeof cssp == 'string') {$(tcell).addClass(cssp);} else {$(tcell).css(cssp);}
}
- if(typeof attrp == 'object') {$(tcell).attr(cssp);}
+ if(typeof attrp == 'object') {$(tcell).attr(attrp);}
}
}
});
@@ -659,10 +659,11 @@
grid.cols[k] = this;
});
};
- var addCell = function(t,row,cell,pos) {
+ var addCell = function(t,row,cell,pos,cssp) {
var td;
td = document.createElement("td");
formatter($(td,t),row,cell,pos,'add');
+ if (cssp) { $(td,t).addClass(cssp); }
row.appendChild(td);
formatCol($(td,t), pos);
};
@@ -761,7 +762,7 @@
};
var addJSONData = function(data,t, rcnt) {
if(data) { var fpos = ts.p.treeANode; rcnt = rcnt || 0; if(fpos===0 && rcnt===0) {$("tbody tr:gt(0)", t).remove();} } else { return; }
- var row,f=[],cur,gi=0,si=0,drows,idn,rd=[],cn=(ts.p.altRows===true) ? 'alt':'';
+ var row,f=[],cur,curcss,gi=0,si=0,drows,idn,rd=[],cn=(ts.p.altRows===true) ? 'alt':'';
ts.p.page = data[ts.p.jsonReader.page];
ts.p.lastpage= data[ts.p.jsonReader.total];
ts.p.records= data[ts.p.jsonReader.records];
@@ -799,9 +800,15 @@
si= 1;
}
if (ts.p.jsonReader.repeatitems === true) {
+ if(ts.p.jsonReader.cssp) {curcss = cur[ts.p.jsonReader.cssp];}
if(ts.p.jsonReader.cell) {cur = cur[ts.p.jsonReader.cell];}
for (var j=0;j<cur.length;j++) {
- addCell(t,row,cur[j],j+gi+si);
+ if (curcss) {
+ addCell(t,row,cur[j],j+gi+si,curcss[j]);
+ } else {
+ // if cssp does not exists - then nothing or default maybe...
+ addCell(t,row,cur[j],j+gi+si);
+ }
rd[ts.p.colModel[j+gi+si].name] = cur[j];
}
} else {
@@ -1184,6 +1191,8 @@
records: "records",
repeatitems: true,
cell: "cell",
+ // CSS class for each cell
+ cssp: "cssp",
id: "id",
userdata: "userdata",
subgrid: {root:"rows", repeatitems: true, cell:"cell"}
PS. Thank you for jqGrid. He has a great future;)
PPS. Sorry about my English. That's all translate.google.com:)
Asche zu Asche...
02:32
Moderators
30/10/2007
Hello,
Thenk you very much for this. I will see if I can include it in the final.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
15:33
15/01/2009
Good time of the day, Tony!
A small change in the code above. Call addClass functions should be done before the call formatter.
In this case, formatting can be managed through the classes too. For example, turn it off in class 'unformat ':)
@@ -659,16 +659,17 @@
grid.cols[k] = this;
});
};
- var addCell = function(t,row,cell,pos) {
+ var addCell = function(t,row,cell,pos,cssp) {
var td;
td = document.createElement("td");
- formatter($(td,t),row,cell,pos,'add');
+ if (cssp) { $(td,t).addClass(cssp); }
+ formatter($(td,t),row,cell,pos,'add');
row.appendChild(td);
formatCol($(td,t), pos);
};
var formatter = function (elem, row, cellval , colpos, act){
var cm = ts.p.colModel[colpos];
- if(cm.formatter) {
+ if ( (cm.formatter) && (!$(elem).hasClass('unformat')) ) {
var opts= {rowId: row.id, colModel:cm,rowData:row};
if($.isFunction( cm.formatter ) ) {
cm.formatter(elem,cellval,opts,act);
With best wishes,
Serg.
Asche zu Asche...
01:43
20/02/2009
Hi,
I wonder if it wouldn't be more interesting to be able to add any attribute to the <td> tag, just by copying the attributes in the <cell> tag from the XML data only (sorry for that).
This would be interresting for style and also for sending parameters. Here is the code I've writen :
1- arround line 683
//var formatCol = function (elem, pos){ // change philbaud_20090220
var formatCol = function (elem, pos,attribs){
var ral = ts.p.colModel[pos].align;
if(ral) { $(elem).css("text-align",ral);}
// add_begin philbaud_20090220
for (var attrib in attribs) {
$(elem).attr(attrib,attribs[attrib]);
}
// add_end philbaud_200890220
if(ts.p.colModel[pos].hidden) {$(elem).css("display","none");}
};
var resizeFirstRow = function (t,er){
$("tbody tr:eq("+er+") td",t).each( function( k ) {
$(this).css("width",grid.headers[k].width+"px");
grid.cols[k] = this;
});
};
//var addCell = function(t,row,cell,pos) { // change philbaud_20090220
var addCell = function(t,row,cell,pos,attribs) {
var td;
td = document.createElement("td");
formatter($(td,t),row,cell,pos,'add');
row.appendChild(td);
//formatCol($(td,t), pos); // change philbaud_20090220
formatCol($(td,t), pos,attribs);
};
2-around line 768
//addCell(t,row,v,i+gi+si); // remove philbaud_20090220
// add-begin philbaud_20090220
var attribs = new Array();
if((0 != this.attributes.length)){
//attrib = "";
for (nCpt = 0; nCpt < this.attributes.length; nCpt ++) {
//attrib += "; " + this.attributes[nCpt].nodeName + ":" + this.attributes[nCpt].nodeValue;
attribs[this.attributes[nCpt].nodeName] = this.attributes[nCpt].nodeValue;
}
}
addCell(t,row,v,i+gi+si,attribs);
// add-begin philbaud_20090220
Sorry, I'm not easy enough with javascript to be sure of my code. But it works on all browser I've tested.
Philippe
02:28
Moderators
30/10/2007
Hello,
The new 3.4 add such philosophy in JSON (read more complex structure). I think it is possible to extend some of this in XML.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
92 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66