对layui中table组件⼯具栏的使⽤详解layui⼯具栏
第⼀步:在table中引⼊table,在table控件下加⼊:
fixed:'right',title:'操作',width:"28%",align:'center',toolbar:"#barlist"
第⼆步:在table标签中加⼊以下js代码:
<script type="text/html" id="barlist">
<!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
{{# if(d.forbidden=="0"){ }}
<a class="layui-btn layui-btn-xs" lay-event="jinyong">禁⽤</a>
{{# } else if(d.forbidden=="1"){}}
<a class="layui-btn layui-btn-xs" lay-event="jiechu">解除</a>
{{# } }}
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
layui框架怎么用第三步:监听⼯具栏
<('tool(listfilter)', function (obj) { //注:tool是⼯具条事件名,test是table原始容器的属性 lay-filter="对应的值"
var data = obj.data //获得当前⾏数据
, layEvent = obj.event; //获得 lay-event 对应的值
if (layEvent === 'detail') {
layer.msg('ID:' + data.id + ' 的查看操作');
} else if (layEvent === 'del') {
obj.del(); //删除对应⾏(tr)的DOM结构
console.log(data.id)
$.ajax({
url: "",
type: "DELETE",
data: {"id": data.id},
dataType: "json",
beforeSend: function (request) {
request.setRequestHeader("Authorization", ken);
},
success: function (data) {
if (de == 200) {
obj.del();
layer.close(index);
layer.msg(data.msg, {icon: 6});
load('list', {});
} else if (de == 401) {
obj.del();
layer.close(index);
layer.msg("登陆已过期,请重登", {icon: 6});
location.href = "./login.html";
}
else {
layer.msg(data.msg, {icon: 5});
}
}
});
layer.close(index);
//向服务端发送删除指令
});
} else if (layEvent === 'edit') {
console.log(data)
x_admin_show('编辑', 'admin-edit.html?id=' + data.id, '900', '500');
/
/ layer.msg('编辑操作');
} else if (layEvent === 'jinyong') {
var x = this;
$(x).text("解除");
$.ajax({
url: "",
type: "PUT",
data: {
"id": data.id,
"forbidden": "1"
},
dataType: "json",
beforeSend: function (request) {
request.setRequestHeader("Authorization", ken);
},
success: function (data) {
if (de == 200) {
layer.close(index);
layer.msg(data.msg, {icon: 6});
} else if (de == 401) {
layer.close(index);
layer.msg("登陆已过期,请重登", {icon: 6});
location.href = "./login.html";
}
else {
layer.msg(data.msg, {icon: 5});
}
}
});
});
// layer.msg('编辑操作');
} else if (layEvent === 'jiechu') {
var x = this;
$(x).text("解除");
$.ajax({
url: "134.175.36.40/api/admin/usual",
type: "PUT",
data: {
"id": data.id,
"forbidden": "0"
},
dataType: "json",
beforeSend: function (request) {
request.setRequestHeader("Authorization", ken);
},
success: function (data) {
if (de == 200) {
layer.close(index);
layer.msg(data.msg, {icon: 6});
} else if (de == 401) {
layer.close(index);
layer.msg("登陆已过期,请重登", {icon: 6});
location.href = "./login.html";
}
else {
layer.msg(data.msg, {icon: 5});
}
}
});
});
}
});
以上这篇对layui中table组件⼯具栏的使⽤详解就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论