用DWRUtil动态生成Table
2009-07-08 22:24
225 查看
前几天,做了一个练习项目,顺便练习了一下DWRUtil当中的方法
其中,cellfuncs是一组方法,是用来返回表格中的内容的,一般是返回td中的内容,有几列则需要几个方法
DWRUtil.removeAllRows(id)是删除表格元素的,通常参数id是一个table的tbody的id
rowCreator是列创建器或者叫列生成器,可以生成一个列,也可以在它的方法内设置tr的属性
而cellCreator很显然就是单元格生成器,可以生成一个td,也可以设置它的属性
但是这里有个缺陷,就是不能为不同的列设置不同的样式
故,我在cellfuncs的方法组中返回的都是带有属性的div,相当于在td中添加了div,这样就达到了想要的效果
其中,cellfuncs是一组方法,是用来返回表格中的内容的,一般是返回td中的内容,有几列则需要几个方法
DWRUtil.removeAllRows(id)是删除表格元素的,通常参数id是一个table的tbody的id
rowCreator是列创建器或者叫列生成器,可以生成一个列,也可以在它的方法内设置tr的属性
而cellCreator很显然就是单元格生成器,可以生成一个td,也可以设置它的属性
但是这里有个缺陷,就是不能为不同的列设置不同的样式
故,我在cellfuncs的方法组中返回的都是带有属性的div,相当于在td中添加了div,这样就达到了想要的效果
function searchGoods(){ try{ DWRUtil.useLoadingMessage("正在查找..."); GoodsHandle.getSearchGoods(goodsName,salerName,goodsStatus,currentPageNum,function(data){ //alert(data.length); var cellfuncs = [ function(data){ var div=document.createElement("div"); div.style.textAlign="left"; div.style.width="100px"; div.id="goodsId"+data.goodsId; var a=document.createElement("a"); a.href=contextPath+"/goods.do?op=toDetail&goodsId="+data.goodsId; a.innerText=data.goodsName; div.appendChild(a); //alert(DWRUtil.toDescriptiveString(div,2)); return div; }, function(data){ var div=document.createElement("div"); div.style.textAlign="left"; div.style.width="200px"; div.innerText=data.goodsDesc; return div; }, function(data){ var div=document.createElement("div"); div.style.width="40px"; div.innerText=data.saler.userName; return div; }, function(data){ var div=document.createElement("div"); div.style.width="50px"; div.innerText=data.goodsPrice; return div; }, function(data){ var div=document.createElement("div"); div.style.width="80px"; var beginTime = data.beginTime; var endTime = data.endTime; beginTime = convertDate(beginTime).substring(0,10); endTime = convertDate(endTime).substring(0,10); div.innerHTML = beginTime+"<br />至<br />"+endTime; return div; } ]; DWRUtil.removeAllRows('tbSearchGoods'); //for(var i=0;i<goodsList.length;i++){ //var goods = goodsList[i]; //alert(DWRUtil.toDescriptiveString(goods,2)); //DWRUtil.setEscapeHtml(false); DWRUtil.addRows('tbSearchGoods', data, cellfuncs,{ rowCreator:function(options) { var row = document.createElement("tr"); //var index = options.rowIndex * 50; //row.setAttribute("id",options.rowData.id); //row.style.collapse = "separate"; //row.style="border:1px dotted #999999; border-collapse:collapse;"; //row.style.color = "rgb(" + index + ",0,0)"; return row; }, cellCreator:function(options) { var td = document.createElement("td"); //var index = 255 - (options.rowIndex * 50); //td.style.backgroundColor = "rgb(" + index + ",255,255)"; //td.style.backgroundColor = "menu"; //td.style.fontWeight = "bold"; //td.style.align = "center"; //td.style="border:1px dotted #999999; border-collapse:collapse;"; td.style.border="1px dotted #999999"; td.style.collapse="collapse"; return td; } } ); //} } ); }catch(e){ } }
相关文章推荐
- JS -- <table> 行号自增,前端动态生成的<tr>
- JQuery动态生成Table表格
- 笔记-js中动态生成、删除table
- 利用table动态生成表格并填充内容/和panel做一个可控制显示/隐藏的小玩意
- js动态生成table 经典
- jquery ajax servlet json(struts2) 动态生成table
- JQuery 动态生成Table表格实例代码
- js动态生成table的一行 并且是复制的当前行 列都一起生成了
- 动态生成table并实现分页效果
- JQUERY动态生成DIV,table等数据
- js动态生成table 合并单元格
- js如何获取table中动态生成的数据
- 【转】ASP.NET中服务器控件Table动态生成表格及其属性介绍
- jsp页面根据json数据动态生成table
- js 根据数组分组动态生成table(相同项合并)
- 后台动态生成table表格
- 动态生成Table
- jquery动态生成改变table的数据内容
- ABAP动态生成经典应用之Table数据Upload 程序
- 动态生成table并实现分页效果心得分享