61jqGrid - 表单预定义函数

简介: 61jqGrid - 表单预定义函数

使用预定义的格式化操作,还是比较方便的添加一行,进行编辑。

HTML代码举例

<html>
  <head>
    <title>jqGrid 实例</title>
  </head>
  <body>
    ···代码省略···
    <table id="frmac"></table> 
    <div id="pfrmac"></div>
    ···代码省略···
  </body>
</html>

javascript代码举例

$(function(){
  pageInit();
});
function pageInit(){
  jQuery("#frmac").jqGrid({
       url:ctx+'/JSONNameData',
    datatype: "json",
       colNames:[' ', 'Inv No', 'Date', 'Client', 'Amount','Tax','Total','Notes'],
       colModel:[
      {name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions',
        formatoptions:{keys:true}},
         {name:'id',  key : true,  index:'id',  width:55},
         {name:'invdate',index:'invdate', width:90},
         {name:'name', index:'name',  width:100},
         {name:'amount',index:'amount', width:80, align:"right", editable:true},
         {name:'tax',index:'tax', width:80, align:"right", editable:true},
         {name:'total',index:'total', width:80,align:"right", editable:true},
         {name:'note',index:'note', width:150, sortable:false, editable:true}
       ],
       rowNum:10,
      width:700,
       rowList:[10,20,30],
       pager: '#pfrmac',
       sortname: 'invdate',
      viewrecords: true,
      sortorder: "desc",
    jsonReader: {
      repeatitems : false
    },
    caption: "Keyboard Navigation",
    height: '100%',
    editurl : ctx+'/RowEditing'
  });
  jQuery("#kfrmac").jqGrid('navGrid','#pfrmac',{edit:false,add:false,del:false});
}

java servlet代码举例

package net.mn886.blog.jqgrid.functionality;
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 JSONNameData
 */
public class JSONNameData extends HttpServlet {
  private static final long serialVersionUID = 1L;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public JSONNameData() {
        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 stub
    doPost(request, response);
  }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String page = request.getParameter("page");
    String jsondata = "{}";
    if("1".equals(page)){
      jsondata = "{" +
          "    \"page\":\"1\"," +
          "    \"total\":2," +
          "    \"records\":\"13\"," +
          "    \"rows\":[" +
          "      {\"id\":\"10\",\"invdate\":\"2007-10-06\",\"name\":\"Client 2\",\"amount\":\"100.00\",\"tax\":\"20.00\",\"total\":\"120.00\",\"note\":null}," +
          "      {\"id\":\"11\",\"invdate\":\"2007-10-06\",\"name\":\"Client 1\",\"amount\":\"600.00\",\"tax\":\"120.00\",\"total\":\"720.00\",\"note\":null}," +
          "      {\"id\":\"9\",\"invdate\":\"2007-10-06\",\"name\":\"Client 1\",\"amount\":\"200.00\",\"tax\":\"40.00\",\"total\":\"240.00\",\"note\":null}," +
          "      {\"id\":\"13\",\"invdate\":\"2007-10-06\",\"name\":\"Client 3\",\"amount\":\"1000.00\",\"tax\":\"0.00\",\"total\":\"1000.00\",\"note\":null}," +
          "      {\"id\":\"8\",\"invdate\":\"2007-10-06\",\"name\":\"Client 3\",\"amount\":\"200.00\",\"tax\":\"0.00\",\"total\":\"200.00\",\"note\":null}," +
          "      {\"id\":\"12\",\"invdate\":\"2007-10-06\",\"name\":\"Client 2\",\"amount\":\"700.00\",\"tax\":\"140.00\",\"total\":\"840.00\",\"note\":null}," +
          "      {\"id\":\"7\",\"invdate\":\"2007-10-05\",\"name\":\"Client 2\",\"amount\":\"120.00\",\"tax\":\"12.00\",\"total\":\"134.00\",\"note\":null}," +
          "      {\"id\":\"6\",\"invdate\":\"2007-10-05\",\"name\":\"Client 1\",\"amount\":\"50.00\",\"tax\":\"10.00\",\"total\":\"60.00\",\"note\":\"\"}," +
          "      {\"id\":\"5\",\"invdate\":\"2007-10-05\",\"name\":\"Client 3\",\"amount\":\"100.00\",\"tax\":\"0.00\",\"total\":\"100.00\",\"note\":\"no tax at all\"}," +
          "      {\"id\":\"4\",\"invdate\":\"2007-10-04\",\"name\":\"Client 3\",\"amount\":\"150.00\",\"tax\":\"0.00\",\"total\":\"150.00\",\"note\":\"no tax\"}" +
          "    ]" +
          "  }";
    }else{
      jsondata = "{" +
          "    \"page\":\"2\"," +
          "    \"total\":2," +
          "    \"records\":\"13\"," +
          "    \"rows\":[" +
          "      {\"id\":\"2\",\"invdate\":\"2007-10-03\",\"name\":\"Client 1\",\"amount\":\"200.00\",\"tax\":\"40.00\",\"total\":\"240.00\",\"note\":\"note 2\"}," +
          "      {\"id\":\"3\",\"invdate\":\"2007-10-02\",\"name\":\"Client 2\",\"amount\":\"300.00\",\"tax\":\"60.00\",\"total\":\"360.00\",\"note\":\"note invoice 3 & and amp test\"}," +
          "      {\"id\":\"1\",\"invdate\":\"2007-10-01\",\"name\":\"Client 1\",\"amount\":\"100.00\",\"tax\":\"20.00\",\"total\":\"120.00\",\"note\":\"note 1\"}" +
          "    ]" +
          "  }";
    }
    response.getWriter().write(jsondata);
  }
}
目录
相关文章
|
2月前
表单的构成与创建、属性
表单的构成与创建、属性。
20 5
|
5月前
|
数据采集 开发框架 .NET
from表单的作用、组成和用法
from表单的作用、组成和用法
|
JavaScript 前端开发 Java
59jqGrid - 列模型模板
59jqGrid - 列模型模板
48 0
|
JavaScript 前端开发 Java
25jqGrid 3.0新特征- 自定义多选
25jqGrid 3.0新特征- 自定义多选
42 0
|
Shell
makefile 自定义,预定义函数
makefile 自定义,预定义函数
94 0
element表单组件的trigger表单验证逻辑规则
校验元素trigger属性值应该怎么选择?
346 0
|
前端开发 JavaScript
javascript将ajax返回的对象数组按照类别字段分组判断是否存在,传递echarts进行图表渲染
javascript将ajax返回的对象数组按照类别字段分组判断是否存在,传递echarts进行图表渲染
95 0
element表单嵌套检验+动态添加
element表单嵌套检验+动态添加
313 0
|
Shell
C编译中如何向代码中传递一个预定义字串
C编译中如何向代码中传递一个预定义字串
73 0
|
JavaScript SQL 前端开发
FineReport 复选框实现多个值查询(使用JS通过文本控件作为值传递实现)
FineReport 复选框实现多个值查询(使用JS通过文本控件作为值传递实现) 给复选框添加编辑后事件,事件使用Javascript,具体的js如下
729 0