layui数据表格重载实现往后台传参

(编辑:jimmy 日期: 2024/11/17 浏览:2)

1、网上的代码:

<div class="demoTable"> 
搜索商户: <div class="layui-inline"> 
<input class="layui-input" name="keyword" id="demoReload" autocomplete="off"> 
</div> 
<button class="layui-btn" data-type="reload">搜索</button></div> 
 
在js加入初始化代码和定义加载方法 
layui.use('table', function(){ 
var table = layui.table; 
 
//方法级渲染 
table.render({ 
elem: '#LAY_table_user' 
,url: 'UVServlet' 
,cols: [[ 
{checkbox: true, fixed: true} 
,{field:'id', title: 'ID', width:80, sort: true, fixed: true} 
,{field:'aid', title: '商户', width:80, sort: true} 
,{field:'uv', title: '访问量', width:80, sort: true,edit:true} 
,{field:'date', title: '日期', width:180} 
,{field:'datatype', title: '日期类型', width:100} 
 
]] 
,id: 'testReload' 
,page: true 
,height: 600 
}); 
 
var $ = layui.$, active = { 
reload: function(){ 
var demoReload = $('#demoReload'); 
 
table.reload('testReload', { 
where: { 
keyword: demoReload.val() 
} 
}); 
} 
}; 
)}; 
 

绑定click点击事件

$('.demoTable .layui-btn').on('click', function(){ var type = $(this).data('type'); //注意顶一个括号中的格式,class用.id用#,中间有一个空格
active[type] "htmlcode">
<!--index.html内容如下-->
{% extends 'common.html'%}
  {% block content %}
    <div class="layui-row">
				<form class="layui-form layui-col-md12 we-search" id="form_gen_data">
					<div class="layui-inline">
            <label class="layui-form-label">手机号</label>
						<input class="layui-input" placeholder="手机号" name="phone" id="phone">
					</div>
 
          <div class="layui-inline">
            <label class="layui-form-label">身份证</label>
						<input class="layui-input" placeholder="身份证" name="idno" id="idno">
					</div>
 
          <div class="layui-inline">
            <label class="layui-form-label">姓名</label>
						<input class="layui-input" placeholder="姓名" name="name" id="name">
					</div>
 
          <div class="layui-inline">
            <label class="layui-form-label">crfuid</label>
						<input class="layui-input" placeholder="crfuid" name="crfuid" id="crfuid">
					</div>
 
				</form>
			</div>
 
			<div class="weadmin-block">
 
				<button class="layui-btn" id="query_extra" style="display:none;">扩展功能</button>
				<button class="layui-btn" id="query_thumb">开始查询</button>
				<button class="layui-btn" id="query_limit">额度查询</button>
				<button class="layui-btn" id="query_member">会员查询</button>
				<button class="layui-btn" id="query_account">账户查询</button>
 
				<button class="layui-btn" id="query_sms" οnclick="return false;" data-type="reload">短信验证码查询</button>
				<div class="layui-collapse" lay-accordion>
 
				 <div class="layui-colla-item">
					<h2 class="layui-colla-title">扩展功能</h2>
					<div class="layui-colla-content">
						{% for business in common_business %}
						<button class="layui-btn layui-btn-danger common_business" id="{{business.business_code}}" data-type="{{business.business_code}}" data-extra="{{business.business_is_extra}}">{{business.business_name}}</button>
						{% endfor %}
					</div>
				 </div>
				</div>
 
 
			</div>
			<div class="layui-collapse">
			 	<div class="layui-colla-item">
					<h2 class="layui-colla-title">日志</h2>
					<div class="layui-colla-content layui-show"><textarea placeholder="" id="log" class="layui-textarea" name="desc"></textarea></div>
 
 
				</div>
 
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">附加信息</h2>
					<div class="layui-colla-content layui-show" id="extra_info">
 
					</div>
				</div>
			</div>
 
 
			<table class="layui-hide" id="table_message" lay-filter="user"></table>
 
      <script type="text/javascript" src="/UploadFiles/2021-04-02/layui.js">
@toolsbp.route('/')
@toolsbp.route('/index',methods=['GET','POST'])
def index():
  
  if request.method=='POST':
    data={}
    data['data']=''
    data['code']=0
    data['msg']='查询成功'
    env=request.form.get('env_tools')
 
    if env is None:
      return json.dumps(data)
    phone=request.form.get('phone')
    where=''
    if phone:
      where="where phone like '%(phone)s'"%{'phone':'%'+phone+'%'}
    dbinfo=env_config.ENV_LIST.get(env.upper()).get('sms_platform')
    dbtool=MysqlPool.MysqlPool(dbinfo.get('db_name'))
    result=dbtool.getAll("select * from %(table_name)s.sms_send_record %(where)s order by create_time desc limit %(page)d,%(pagesize)d;"%{'where':where,'table_name':dbinfo.get('table_name'),'page':int(request.form.get('page'))-1,'pagesize':int(request.form.get('limit'))})
    data['data']=result
    if result:
      data['count']=len(result)
    else:
      data['count']=0
    return json.dumps(data,cls=MysqlPool.DateEncoder)
  return render_template('tools/index.html')

(3)页面功能如下:

layui数据表格重载实现往后台传参

以上这篇layui数据表格重载实现往后台传参就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。