热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

69jqGrid层级加载时展开所有行

当行被加载时,我们可以自动的展开所有的行。这样做是通过一个参数实现的。具体请查看代码。HTML代码举例jqGrid实例

当行被加载时,我们可以自动的展开所有的行。这样做是通过一个参数实现的。具体请查看代码。
在这里插入图片描述


HTML代码举例

···代码省略···

···代码省略···


Javascript代码举例

$(function(){pageInit();
});
function pageInit(){jQuery("#sg2").jqGrid({url:ctx+'/JSONData',datatype: "json",height: 190,colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],colModel:[{name:'id',index:'id', width:55},{name:'invdate',index:'invdate', width:90},{name:'name',index:'name', width:100},{name:'amount',index:'amount', width:80, align:"right"},{name:'tax',index:'tax', width:80, align:"right"},{name:'total',index:'total', width:80,align:"right"},{name:'note',index:'note', width:150, sortable:false}],rowNum:8,rowList:[8,10,20,30],pager: '#psg2',sortname: 'id',viewrecords: true,sortorder: "desc",multiselect: false,subGrid: true,caption: "Custom Icons in Subgrid",// define the icons in subgridsubGridOptions: {"plusicon" : "ui-icon-triangle-1-e","minusicon" : "ui-icon-triangle-1-s","openicon" : "ui-icon-arrowreturn-1-e",//expand all rows on load"expandOnLoad" : true},subGridRowExpanded: function(subgrid_id, row_id) {var subgrid_table_id, pager_id;subgrid_table_id = subgrid_id+"_t";pager_id = "p_"+subgrid_table_id;$("#"+subgrid_id).html("

");jQuery("#"+subgrid_table_id).jqGrid({url:ctx+"/SubGrid?q=2&id="+row_id,datatype: "json",colNames: ['No','Item','Qty','Unit','Line Total'],colModel: [{name:"num",index:"num",width:80,key:true},{name:"item",index:"item",width:130},{name:"qty",index:"qty",width:70,align:"right"},{name:"unit",index:"unit",width:70,align:"right"},{name:"total",index:"total",width:70,align:"right",sortable:false}],rowNum:20,pager: pager_id,sortname: 'num',sortorder: "asc",height: '100%'});jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false})}});jQuery("#sg2").jqGrid('navGrid','#psg2',{add:false,edit:false,del:false});}

Master java servlet代码举例

package net.mn886.blog.jqgrid.loadding_data;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** Servlet implementation class JSONData*/
public class JSONData extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public JSONData() {super();// TODO Auto-generated constructor stub}@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubdoPost(req,resp);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubString jsondata = "{\"page\":\"1\"," +" \"total\":2," +" \"records\":\"13\"," +" \"rows\":" +" [" +" {" +" \"id\":\"13\"," +" \"cell\":" +" [\"13\",\"2007-10-06\",\"Client 3\",\"1000.00\",\"0.00\",\"1000.00\",null]" +" }," +" {" +" \"id\":\"12\"," +" \"cell\":" +" [\"12\",\"2007-10-06\",\"Client 2\",\"700.00\",\"140.00\",\"840.00\",null]" +" }," +" {" +" \"id\":\"11\"," +" \"cell\":" +" [\"11\",\"2007-10-06\",\"Client 1\",\"600.00\",\"120.00\",\"720.00\",null]" +" }," +" {" +" \"id\":\"10\"," +" \"cell\":" +" [\"10\",\"2007-10-06\",\"Client 2\",\"100.00\",\"20.00\",\"120.00\",null]" +" }," +" {" +" \"id\":\"9\"," +" \"cell\":" +" [\"9\",\"2007-10-06\",\"Client 1\",\"200.00\",\"40.00\",\"240.00\",null]" +" }," +" {" +" \"id\":\"8\"," +" \"cell\":" +" [\"8\",\"2007-10-06\",\"Client 3\",\"200.00\",\"0.00\",\"200.00\",null]" +" }," +" {" +" \"id\":\"7\"," +" \"cell\":" +" [\"7\",\"2007-10-05\",\"Client 2\",\"120.00\",\"12.00\",\"134.00\",null]" +" }," +" {" +" \"id\":\"6\"," +" \"cell\":" +" [\"6\",\"2007-10-05\",\"Client 1\",\"50.00\",\"10.00\",\"60.00\",\"\"]" +" }," +" {" +" \"id\":\"5\"," +" \"cell\":" +" [\"5\",\"2007-10-05\",\"Client 3\",\"100.00\",\"0.00\",\"100.00\",\"no tax at all\"]" +" }," +" {" +" \"id\":\"4\"," +" \"cell\":" +" [\"4\",\"2007-10-04\",\"Client 3\",\"150.00\",\"0.00\",\"150.00\",\"no tax\"]" +" }" +" ]," +" \"userdata\":{\"amount\":3220,\"tax\":342,\"total\":3564,\"name\":\"Totals:\"}" +" }";response.getWriter().write(jsondata);}}

Subgrid java servlet代码举例

package net.mn886.blog.jqgrid.advanced;import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** Servlet implementation class SubGrid*/
public class SubGrid extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public SubGrid() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoPost(request,response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubString id = request.getParameter("id");int iId = Integer.parseInt(id);String jsondata = "{}";switch (iId) {case 13:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"1\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 13\",\"1.00\",\"1000.00\",\"1 000.00\"]" +" }" +" ]" +" }";break;case 12:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"1.00\",\"400.00\",\"400.00\"]" +" }," +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 4\",\"1.00\",\"300.00\",\"300.00\"]" +" }" +" ]" +" }";break;case 11:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"4\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 1\",\"2.00\",\"100.00\",\"200.00\"]" +" }," +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"3.00\",\"50.00\",\"150.00\"]" +" }," +" {" +" \"id\":\"3\"," +" \"cell\":[\"3\",\"item 3\",\"1.00\",\"50.00\",\"50.00\"]" +" }," +" {" +" \"id\":\"4\"," +" \"cell\":[\"4\",\"item 4\",\"1.00\",\"200.00\",\"200.00\"]" +" }" +" ]" +" }";break;case 10:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 4\",\"1.00\",\"70.00\",\"70.00\"]" +" }," +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 5\",\"3.00\",\"10.00\",\"30.00\"]" +" }" +" ]" +" }";break;case 9:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 3\",\"1.00\",\"60.00\",\"60.00\"]" +" }," +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 6\",\"1.00\",\"140.00\",\"140.00\"]" +" }" +" ]" +" }";break;case 8:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"3\"," +" \"rows\":[" +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"1.00\",\"120.00\",\"120.00\"]" +" }," +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 3\",\"1.00\",\"50.00\",\"50.00\"]" +" }," +" {" +" \"id\":\"3\"," +" \"cell\":[\"3\",\"item 3\",\"1.00\",\"30.00\",\"30.00\"]" +" }" +" ]" +" }";break;case 7:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 1\",\"1.00\",\"100.00\",\"100.00\"]" +" }," +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 5\",\"2.00\",\"10.00\",\"20.00\"]" +" }" +" ]" +" }";break;case 6:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"1\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 4\",\"1.00\",\"50.00\",\"50.00\"]" +" }" +" ]" +" }";break;case 5:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"1\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 3\",\"1.00\",\"100.00\",\"100.00\"]" +" }" +" ]" +" }";break;case 4:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 1\",\"1.00\",\"100.00\",\"100.00\"]" +" }," +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"1.00\",\"50.00\",\"50.00\"]" +" }" +" ]" +" }";break;case 3:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 3\",\"1.00\",\"100.00\",\"100.00\"]" +" }," +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 4\",\"1.00\",\"200.00\",\"200.00\"]" +" }" +" ]" +" }";break;case 2:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 1\",\"2.00\",\"20.00\",\"40.00\"]" +" }," +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"4.00\",\"40.00\",\"160.00\"]" +" }" +" ]" +" }";break;case 1:jsondata = "{" +" \"page\":\"1\"," +" \"total\":1," +" \"records\":\"2\"," +" \"rows\":[" +" {" +" \"id\":\"1\"," +" \"cell\":[\"1\",\"item 1\",\"1.00\",\"20.00\",\"20.00\"]" +" }," +" {" +" \"id\":\"2\"," +" \"cell\":[\"2\",\"item 2\",\"2.00\",\"40.00\",\"80.00\"]" +" }" +" ]" +" }";break;default:break;}response.getWriter().write(jsondata);}}

推荐阅读
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • Voicewo在线语音识别转换jQuery插件的特点和示例
    本文介绍了一款名为Voicewo的在线语音识别转换jQuery插件,该插件具有快速、架构、风格、扩展和兼容等特点,适合在互联网应用中使用。同时还提供了一个快速示例供开发人员参考。 ... [详细]
  • Ihavethefollowingonhtml我在html上有以下内容<html><head><scriptsrc..3003_Tes ... [详细]
  • Java实战之电影在线观看系统的实现
    本文介绍了Java实战之电影在线观看系统的实现过程。首先对项目进行了简述,然后展示了系统的效果图。接着介绍了系统的核心代码,包括后台用户管理控制器、电影管理控制器和前台电影控制器。最后对项目的环境配置和使用的技术进行了说明,包括JSP、Spring、SpringMVC、MyBatis、html、css、JavaScript、JQuery、Ajax、layui和maven等。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • javascript  – 概述在Firefox上无法正常工作
    我试图提出一些自定义大纲,以达到一些Web可访问性建议.但我不能用Firefox制作.这就是它在Chrome上的外观:而那个图标实际上是一个锚点.在Firefox上,它只概述了整个 ... [详细]
  • Html5-Canvas实现简易的抽奖转盘效果
    本文介绍了如何使用Html5和Canvas标签来实现简易的抽奖转盘效果,同时使用了jQueryRotate.js旋转插件。文章中给出了主要的html和css代码,并展示了实现的基本效果。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • 从零基础到精通的前台学习路线
    随着互联网的发展,前台开发工程师成为市场上非常抢手的人才。本文介绍了从零基础到精通前台开发的学习路线,包括学习HTML、CSS、JavaScript等基础知识和常用工具的使用。通过循序渐进的学习,可以掌握前台开发的基本技能,并有能力找到一份月薪8000以上的工作。 ... [详细]
  • 本文介绍了如何使用jQuery和AJAX来实现动态更新两个div的方法。通过调用PHP文件并返回JSON字符串,可以将不同的文本分别插入到两个div中,从而实现页面的动态更新。 ... [详细]
  • Android实战——jsoup实现网络爬虫,糗事百科项目的起步
    本文介绍了Android实战中使用jsoup实现网络爬虫的方法,以糗事百科项目为例。对于初学者来说,数据源的缺乏是做项目的最大烦恼之一。本文讲述了如何使用网络爬虫获取数据,并以糗事百科作为练手项目。同时,提到了使用jsoup需要结合前端基础知识,以及如果学过JS的话可以更轻松地使用该框架。 ... [详细]
  • Node.js学习笔记(一)package.json及cnpm
    本文介绍了Node.js中包的概念,以及如何使用包来统一管理具有相互依赖关系的模块。同时还介绍了NPM(Node Package Manager)的基本介绍和使用方法,以及如何通过NPM下载第三方模块。 ... [详细]
author-avatar
乐果Meng_501
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有