64jqGrid - 在搜索中显示查询条件

简介: 64jqGrid - 在搜索中显示查询条件

搜索查询语句可以展示给用户。

HTML代码举例

<html>
  <head>
    <title>jqGrid 实例</title>
  </head>
  <body style="font-size: 10px;">
    ···代码省略···
    <table id="grps1"></table> 
    <div id="pgrps1"></div>
    ···代码省略···
  </body>
</html>

javascript代码举例

$(function(){
  pageInit();
});
function pageInit(){
  jQuery("#grps1").jqGrid({
       url:ctx+'/JSONNameData',
    datatype: "json",
       colNames:['Inv No', 'Date', 'Client', 'Amount','Tax','Total','Notes'],
       colModel:[
         {name:'id',  key : true,  index:'id',  width:55, searchtype:"integer"},
         {name:'invdate',index:'invdate', width:90},
         {name:'name', index:'name',  width:100},
         {name:'amount',index:'amount', width:80, align:"right", searchtype:"number"},
         {name:'tax',index:'tax', width:80, align:"right", searchtype:"number"},
         {name:'total',index:'total', width:80,align:"right", searchtype:"number"},
         {name:'note',index:'note', width:150, sortable:false}
       ],
       rowNum:10,
      width:700,
       rowList:[10,20,30],
       pager: '#pgrps1',
       sortname: 'invdate',
      viewrecords: true,
      sortorder: "desc",
    jsonReader: {
      repeatitems : false
    },
    caption: "Show query in search",
    height: '100%'
  });
  jQuery("#grps1").jqGrid('navGrid','#pgrps1',
  {edit:false,add:false,del:false},
  {},
  {},
  {},
  {multipleSearch:true, multipleGroup:true, showQuery: true}
  );

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);
  }
}
目录
相关文章
|
JavaScript 数据格式
10jqGrid - 搜索操作
10jqGrid - 搜索操作
53 0
|
JavaScript 前端开发 Java
65jqGrid - 搜索中验证数据
65jqGrid - 搜索中验证数据
49 0
|
JSON JavaScript 前端开发
82jqGrid - 搜索
82jqGrid - 搜索
32 0
|
JavaScript 前端开发 Java
63jqGrid - 复杂搜索
63jqGrid - 复杂搜索
53 0
|
JavaScript 前端开发 Java
67jqGrid - 搜索操作工具栏
67jqGrid - 搜索操作工具栏
59 0
|
JavaScript 前端开发 Java
66jqGrid - 搜索模板
66jqGrid - 搜索模板
38 0
接口数据多条件搜索(模糊查询)
接口数据多条件搜索(模糊查询)
247 0
|
自然语言处理 索引
ES 匹配多个搜索条件和精确查询
ES 匹配多个搜索条件和精确查询
|
JavaScript 算法 前端开发
layui框架实战案例(16):xm-select下拉多选插件实战记录(远程搜索、过滤、翻页、单选、提示文字)
layui框架实战案例(16):xm-select下拉多选插件实战记录(远程搜索、过滤、翻页、单选、提示文字)
961 0
|
JavaScript
js多条件筛选(可单条件搜索还可以模糊查询)
js多条件筛选(可单条件搜索还可以模糊查询)
299 0