Created
June 5, 2011 04:52
-
-
Save geothird/1008660 to your computer and use it in GitHub Desktop.
Prints extjs store to html table.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var head = false; | |
var cols = 0; | |
function printStore(store,th) { | |
var a = store.data.items; | |
var h = new Array(); | |
var d = new Array(); | |
for (var i=0; i < a.length; i++) { | |
for (var propName in a[i].data) { | |
if (!(a[i].data[propName] instanceof Function)) { | |
d.push(a[i].data[propName]); | |
if(i<1) { | |
h.push(propName); | |
cols++; | |
} | |
} | |
} | |
}; | |
var col = 0; | |
var rw = new Array(); | |
var rs = new Array(); | |
for (var i=0; i < d.length; i++) { | |
if(col<cols) { | |
rw.push(d[i]); | |
col++; | |
if(col==cols) { | |
col = 0; | |
rs.push(rw); | |
rw = new Array(); | |
} | |
} | |
}; | |
var ret = ""; | |
if(th) | |
ret = "<html><head><title>Print</title></head><body>"; | |
ret += t(h,rs,th); | |
if(th) | |
ret += "</body></html>"; | |
head = false; | |
cols = 0; | |
return ret; | |
} | |
function t(h,d,th) { | |
if(th) | |
return "<table border=\"1\">"+tc(h,d,th)+"</table>"; | |
else | |
return "<table>"+tc(h,d,th)+"</table>"; | |
} | |
function tc(h,d,ih) { | |
var ret = ""; | |
if(!head) { | |
ret += "<tr>"; | |
for (var i=0; i < h.length; i++) { | |
if(ih) | |
ret += th(h[i]); | |
else | |
ret += td(h[i]); | |
}; | |
ret += "</tr>"; | |
head = true; | |
} | |
for (var i=0; i < d.length; i++) { | |
ret += "<tr>"+tdd(d[i])+"</tr>"; | |
}; | |
return ret; | |
} | |
function tdd(d) { | |
var ret = ""; | |
for (var i=0; i < d.length; i++) { | |
ret += td(d[i]); | |
}; | |
return ret; | |
} | |
function td(d) { | |
return "<td>"+d+"</td>"; | |
} | |
function th(h) { | |
return "<th>"+h+"</th>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment