当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 使用Easyui实现查询条件的后端传递并自动刷新表格的两种方法

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

2019年09月14日  | 移动技术网IT编程  | 我要评论

搜索框如下:

  • 通过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实现查询条件的后端传递并自动刷新表格的两种方法,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网