(function(window){ var grid = { /* * 产生表格主体 */ gridbody : function(thead, theadname, colswidth, infopage, startIndex, tbody) { var numcol = thead.length, numrow = tbody.length, gridstr = '<div id="grid"><table class="dataTable" style="100%;"><tbody><tr class="odd_row">', i, j; //产生表头 //alert(gridstr); gridstr += '<td style="' + colswidth[0] + ';">' + theadname[0] + '</td>'; for (i = 1; i < numcol; i++) { gridstr += '<td style="' + colswidth[i] + ';">' + theadname[i] + '</td>'; } //产生每一行 for (i = 0; i < numrow; i++) { var odd_even; if(i%2){ odd_even = ' class="even_row" '; }else{ odd_even = ' class="even_row2" '; } gridstr += '<tr ' + odd_even +'><td>' + (startIndex + i) + '</td>'; for (j = 1; j < numcol; j++) { if (j == infopage.hrefcol) { gridstr += '<td><a href="' + infopage.infohref + '?' + infopage.argument + '=' + tbody[i][infopage.argument] + '">' + tbody[i][thead[j]] + '</a></td>'; } else { gridstr += '<td>' + tbody[i][thead[j]] + '</td>'; } } gridstr += '</tr>'; } gridstr += '</tbody></table></div>'; return gridstr; }, /* * 产生表格分页栏, 可传递点击分页时触发的函数名,参数仍是当前页的id * para = {pagecount : 3, curpage : 1, clickAction : "myfunction"} */ gridfoot : function(para){ var i; var pageBarStr = '<div>'; if(para.pagecount < 8){ for(i = 1; i <= para.pagecount; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } }else if(para.pagecount == 8){ if(para.curpage < 5){ for(i = 1; i < 7; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } pageBarStr += '...<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">8</a>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">1</a>...'; for(i = 3; i <= 8; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } } }else{ //pagecount > 8 if(para.curpage < 5){ for(i = 1; i < 7; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } pageBarStr += '...<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + para.pagecount +'</a>'; }else if(para.curpage > para.pagecount - 4){ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">1</a>...'; for(i = para.pagecount - 5; i <= para.pagecount; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">1</a>...'; for(i = para.curpage - 2; i < para.curpage + 3; i++){ if(i == para.curpage){ pageBarStr += '<strong>' + i + '</strong>'; }else{ pageBarStr += '<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + i +'</a>'; } } pageBarStr += '...<a href="javascript:;" onclick="' + para.clickAction +'(this.innerHTML)">' + para.pagecount +'</a>'; } } pageBarStr += '</div>'; return pageBarStr; } }; window.grid = grid; })(window);