layui table 的黑坑

layui table

//JavaScript代码区域
var basepath='<%=basePath%>';

$(function(){
pageQuery(1);
});
layui.use('element', function(){
  var element = layui.element;  
});
	
//时间日期选择开始//
layui.use('laydate', function(){
  var laydate = layui.laydate;
  //双控件
  laydate.render({
    elem: '#test1' //指定元素
    ,type: 'datetime'
    ,trigger: 'click'
    ,lang: 'en'
    //,lang: 'en'
    ,range: true //开启日期范围,默认使用“_”分割
    ,done: function(value, date, endDate){
      console.log(value, date, endDate);
    }
    ,change: function(value, date, endDate){
      console.log(value, date, endDate);
    }
  });
  

  //<strong>同时绑定多个</strong>
  lay('.test-item').each(function(){
    laydate.render({
      elem: this
      ,trigger: 'click'
    });
  });


});
//时间日期选择结束//
	
//分页开始//
//分页器
var dataObj = {
    page_enterprise : 1,
    //选择每页显示的数据条数
    limit_enterprise: 10,
};
function pageQuery(pageno,unitNameOrPhone) {

  var unitNameOrPhone=$("input[name='unitNameOrPhone']").val();
  var startTime=$("input[name='startTime']").val();
  var endTime=$("input[name='endTime']").val();
  var checkList = [];
      layui.use('table', function(){
        var table = layui.table;        
        table.render({
          elem: '#layui-table'
          ,method:'POST'
          ,contentType: 'application/json; charset=UTF-8'
          ,url: basepath+'info/queryParameter.do?unitNameOrPhone='+unitNameOrPhone+'&startTime='+startTime+'&endTime='+endTime
          ,cols: [[
            {checkbox : true, width: 40,}
            ,{field:'regTime', width: 110, title: '登记时间'}
            ,{field:'unitName', width:147, title: '单位名称'}
            ,{field:'addr', width: 80, title: '地区'}
            ,{field:'dueTime', title: '到期时间', width: 110}
            ,{field:'webCount', width:80, title: '网站数'}
            ,{field:'phone', width:120, title: '联系电话'}
            ,{field:'email', width:120, title: '邮箱'}
            ,{field:'linkMan', width:80, title: '联系人'}
            ,{field:'lastreqtime', width:100, title: '最近推送'}
            ,{field:'state', width:80, title: '状态'}
          ]]
          ,page: true
        });
        //监听表格复选框选择
          table.on('checkbox(demo)', function(obj){
            if (obj.type == 'all') {
            	checkList.push('all');
            } else {
              if(obj.checked) {
                checkList.push(obj.data);
              } else {
                var _index = checkList.indexOf(obj.data);
                checkList.splice(_index, 1);
              }
            }
          });

        var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
  
  //触发事件
      var active = {
        test5: function(){
          layer.open({
            title:'新增服务单位信息',
            type: 2,
            skin: 'layui-layer-rim', 
            area: ['700px', '420px'], 
            content: 'info/newadd.do'
          });
        },
        test6: function(){ //修改
            if(checkList.length==1 && checkList[0]!='all' ){
					layer.open({
							title : '修改单位信息',
							type : 2,
							skin : 'layui-layer-rim',
							area : [ '700px', '420px' ],
							content : 'info/newupdate.do?id='+checkList[0].id
						});
					} else {
						layer.alert('请勾选一条数据');
					}
				},
		test7 : function() { //删除
			if(checkList.length==1 && checkList[0]!='all' ){
				 	 layer.confirm('确定要删除'+checkList.length+'条数据?', {
               			btn: ['确定','取消'], //按钮
           			}, function(){
           				layer.alert('删除成功');
               			ajaxDelete(checkList[0].id);
           			});
				}else{
					layer.alert('请勾选一条数据');
				}
				}
			};
			$('.demo').on('click', function() {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});

		});
	}
function ajaxDelete(id){
	 $.ajax({
    	 url :basepath+'info/deleteUnitInfo.do?id='+id,
           type : "post",
           dataType : 'json',
           success : function(result){
           		if (result.msg) {
           			layer.msg("删除成功");
					window.parent.location.reload();
				}else {
					layer.msg("删除失败");
				}
           }
    });
}

layui默认get请求,后台必须进行编码转换:

String unitName =new String(request.getParameter("unitName").getBytes("ISO-8859-1"), "utf-8");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值