layui停止更新_layui关闭弹层并刷新父页面表格

该博客展示了如何使用layui框架进行页面弹层管理,包括获取iframe层索引并关闭,以及刷新父页面表格的操作。同时,详细介绍了如何利用layui的table模块进行数据渲染、事件监听以及各种操作,如筛选、删除和编辑角色等。
摘要由CSDN通过智能技术生成

//先得到当前iframe层的索引

var index = parent.layer.getFrameIndex(window.name);

//再执行关闭

parent.layer.close(index);

//关闭父级页面的表格

parent.layui.table.reload('vehicleAlertInfoTableReload',{page:{curr:1}});

其他参考layui.use(['tree', 'util','table'], function(){

var tree = layui.tree

,layer = layui.layer

,util = layui.util

,table = layui.table

,$ = layui.$;

var reportId = "{{ $_GET['reportId'] }}";

table.render({

elem: '#pbi_role'

,url:"地址"

,cols: [[

{type:'radio',event:'roleRadio'}

,{field:'name', title: 'Role Name'}

,{field:'description', title: 'Description'}

]]

,page: false

,id:'roleTable'

,height: 'full-160'

, done: function (res, curr, count) {

$.each(res.data, function (key, value) {

// console.log(key, value)

if (value.if_checked == '1') {

$(".layui-table-view[lay-id='roleTable'] .layui-table-body tr[data-index='"+key+"'] .layui-form-radio").click();

}

});

}

});

table.render({

elem: '#users'

,url:"地址"

,cols: [[

{type:'checkbox'/*,LAY_CHECKED:true*/}

,{field:'id', title: 'ID',width:80}

,{field:'username', title: '8ID'}

,{field:'name', title: 'Name'}

]]

,height: 'full-160'

,id:'userTable'

, done: function (res, curr, count) {

// console.log(res, curr, count)

// //可以自行添加判断的条件是否选中

// //这句才是真正选中,通过设置关键字LAY_CHECKED为true选中,这里只对第一行选中

// res.data[0]["LAY_CHECKED"]='true';

// //下面三句是通过更改css来实现选中的效果

// var index= res.data[0]['LAY_TABLE_INDEX'];

// $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);

// $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');

// $(".layui-table-view[lay-id='tableDataId'] .layui-table-body tr[data-index = '0' ] .layui-form-radio").click();

}

,page: false

});

table.on('tool(pbi_role)', function(obj){

var data = obj.data;

var tr = obj.tr;

if(obj.event === 'roleRadio' && ($(this).find('input').is(':checked')== true)){

// user_render(data.id)

user_render({id:data.id})

}

});

function user_render(data){

console.log(data);

table.reload('userTable', {

where: {

id: data.id

}

}, 'data');

}

//search

$('#search_user').on('click', function(){

var checkStatus = table.checkStatus('roleTable')

,data = checkStatus.data;

var id;

if (data.length !== 0){

var id = data[0]['id'];

}

var username = $('#username').val();

var filter = {id:id,username:username};

// console.log(filter);

user_render(filter);

});

var active = {

deleteRole: function(){

var checkStatus = table.checkStatus('roleTable')

,data = checkStatus.data;

var info = data[0];

if (info == undefined){

layer.tips('Please choose one!', $(".layui-table-view[lay-id='roleTable'] .layui-table-body"), {

tips: [3,'#FF5722'],

time:5000,

});

return false;

}

layer.confirm('Are you sure to delete ['+info.name+']?', {

title:'Delete',

btn: ['Confirm','Cancel'] //按钮

}, function(){

var url = "地址?id="+info.id;

$.ajaxSetup({

headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }

});

$.ajax({

url:url,

data:{id:info.id},

type:'post',

success:function(res) {

if(res.code == 200) {

table.reload('roleTable');

layer.msg('successful', {icon: 1});

} else {

layer.msg(res.msg, {icon: 5,time:2000});

}

}

})

return false; //

}, function(){

});

},

editRole: function(){

var checkStatus = table.checkStatus('roleTable')

,data = checkStatus.data;

var info = data[0];

if (info == undefined){

layer.tips('Please choose one !', $(".layui-table-view[lay-id='roleTable'] .layui-table-body"), {

tips: [3,'#FF5722'],

time:5000,

});

return false;

}

var url = "地址?id="+info.id;

layer.open({

type: 2,

title: info.name,

shadeClose: false,

maxmin: false,

shade: 0.7,

area: ["40%", "90%"],

offset: 'auto',

anim: 0,

content: url

});

},

addUser:function () {

var checkStatus = table.checkStatus('roleTable')

,data = checkStatus.data;

var info = data[0];

// console.log(info);

if (info == undefined){

layer.tips('Please choose one !', $(".layui-table-view[lay-id='roleTable'] .layui-table-body"), {

tips: [3,'#FF5722'],

time:5000,

});

return false;

}

var url = "地址?id="+info.id+"&reportId="+info.reportId;

layer.open({

type: 2,

title: info.name,

shadeClose: false,

maxmin: false,

shade: 0.7,

area: ["40%", "90%"],

offset: 'auto',

anim: 0,

content: url

});

},

deleteUser:function () {

var checkStatus = table.checkStatus('userTable')

,data = checkStatus.data;

console.log(data);

if (data){

layer.tips('Please choose !', $(".layui-table-view[lay-id='userTable'] .layui-table-body"), {

tips: [3,'#FF5722'],

time:5000,

});

return false;

}

}

};

$('.headerButton .layui-btn').on('click', function(){

var type = $(this).data('type');

active[type] ? active[type].call(this) : '';

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值