1. 在表格的下方添加一个链接【显示/隐藏列】
<a href="#" οnclick="func11();">【显示/隐藏列】</a>
2. 用javascript写一段函数
<script>
function func11() {
//iframe窗
parent.layer.open({
type: 2,
title: false,
closeBtn: 1, //不显示关闭按钮
shade: [0],
area: ['340px', '215px'],
offset: 'auto', //右下角弹出
time: 1000, //2秒后自动关闭
shift: 2,
content: ['', 'yes'], //iframe的url,no代表不显示滚动条
end: function(){ //此处用于演示
parent.layer.open({
type: 2,
title: '',
shadeClose: true,
shade: false,
maxmin: false, //开启最大化最小化按钮
area: ['300px', '450px'],
offset: '200px',
content: '/deviceman/showhidecolumns',
end: function(){
location.reload();
}
});
}
});
}
</script>
3. 后端写一个接view.py
def showhidecolumns(request):
initial_list = ['host_name', 'service_tag','motable__hosttype_list__name','motable','receive_date','user_list__dept_list__bl_list__bl_name','user_list__dept_list__dept_name','user_list', 'pcstatustable', \
'site_list','asset_code','ownername','user_list__work_category__name']
if request.method == 'GET':
includes_list=request.session.get('includes_list',[])
if len(includes_list) > 0:
initial_list = includes_list
columns_list = request.session.get('columns_list_session')
#print(columns_list)
obj = showhidecolumnsform(request,initial={'sh':initial_list})
return render(request, 'showhidecolumns.html' ,{'obj':obj})
else:
obj = request.POST.getlist('sh')
request.session['includes_list']=obj
#print('obj',obj)
excludes = request.session.get('columns_list_session')
excludes_dict = dict(excludes)
for i in obj:
#print(str(i))
del excludes_dict[i]
#print(tuple(excludes_dict.keys()))
request.session['excludes_list'] = tuple(excludes_dict.keys())
return HttpResponse('<br><br> <div style="text-align:center"><h3>设置成功!</h3></div>')
|