//测试数据 var dataJsonStr='{tablename:"",rows:[{"姓名":"曹操","性别":"男","年龄":"51","住址":"许昌"},{"姓名":"诸葛亮","性别":"男","年龄":"40","住址":"南阳"},{"姓名":"周瑜","性别":"男","年龄":"40","住址":"江东"},{"姓名":"大乔","性别":"女","年龄":"30","住址":"江东"},{"姓名":"小乔","性别":"女","年龄":"28","住址":"江东"},{"姓名":"曹操","性别":"男","年龄":"51","住址":"许昌"},{"姓名":"诸葛亮","性别":"男","年龄":"40","住址":"南阳"},{"姓名":"周瑜","性别":"男","年龄":"40","住址":"江东"},{"姓名":"大乔","性别":"女","年龄":"30","住址":"江东"},{"姓名":"小乔","性别":"女","年龄":"28","住址":"江东"}]}'; //清空数据 $('#test').DataGridClear(); //设定行样式 $('#test').DataGridSetItemClass("tr1","tr2","trhover"); //绑定数据,并设置宽度高度 $('#test').DataGrid("100%",200,dataJsonStr);
结构示意图:
如何根据HTML模板创建DataGrid整个结构? 1.首先创建 表头 主体 等各区域:
代码如下:
TableBody.addClass('TableBody'); TableBody.wrap(""); var MyTable=$('#'+MyTableId); TableBody.data('MyTable',MyTable); TableBody.before("
"); var TableHead=MyTable.find(".TableHead"); TableBody.data('TableHead',TableHead); TableBody.wrap(''); TableHead.wrap(""); var TableBodyArea=MyTable.find('.TableBodyArea'); var TableHeadArea=MyTable.find('.TableHeadArea'); TableBody.data('TableBodyArea',TableBodyArea); TableBody.data('TableHeadArea',TableHeadArea);