使用Easyui实现查询条件的后端传递并自动刷新表格的两种方法

搜索框如下:

  • 通过datagrid的load方法直接传递参数并自动刷新表格
  • 通过ajax的post函数传递参数并通过loadData方法将数据初始化到表格中

js代码(搜索按钮的点击事件部分):

$("#standardQueryBtn").click(function(){//点击搜索按钮的触发事件
      if($("#offerid").val() != ""){//判断id搜索框的值是否为空
        $("#dg").datagrid('load',{//调用load方法传递参数,从服务器加载新数据
          "offer.id":$("#offerid").val(),//将搜索框的值赋给offer.id并传到后端
          "flag":'qid',//传递一个flag值用于判断执行何种操作
          });  

        }else if($("#offername").val() != ""){//判断name搜素框的值是否为空
          $.post("${pageContext.request.contextPath}/OfferServlet",//通过ajax的post函数传递flag和offername值
              {flag:"qname","offer.name":$("#offername").val()},
              function(ons){//回调函数处理
                var json = JSON.parse(ons);//将返回的字符串转换为JSON
                $('#dg').datagrid('loadData',json);//将表格数据初始化方式更新
              });
        }
    
      });

jsp代码(只包含按钮和搜索框的toolbar):

 <div id="toolbar">
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newOffer()">新增商品</a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editOffer()">编辑商品</a>
    <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyOffer()">删除商品</a><br>
    商品ID:<input type="text" name="offer.id" id="offerid" /> 
    商品名称:<input type="text" id="offername"/> 
    <a id="standardQueryBtn" href="javascript:void(0)" rel="external nofollow" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a> 
  </div>

总结

以上所述是小编给大家介绍的使用Easyui实现查询条件的后端传递并自动刷新表格的两种方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对来客网网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!