列表界面-自定义列功能

This commit is contained in:
chiguangxu
2018-03-13 16:10:58 +08:00
parent 939f7d68eb
commit 256c2b9f9b
5 changed files with 205 additions and 67 deletions

View File

@@ -12,8 +12,17 @@ $(document).ready(function() {
$("a").bind("focus",function() {
if(this.blur) {this.blur()};
});
//所有下拉框使用select2 - 排除class为noSelect2的<select>元素
//$("select:not(.noSelect2)").select2();
//界面中存在<a class="setfields">自定义列按钮,初始化自定义列功能
if($("a").hasClass("setfields")) {
customColumnInit();
//绑定自定义按钮事件
$(".setfields").click(function(){
customColumnClick();
});
}
}catch(e){
// blank
@@ -327,4 +336,103 @@ function fiterPanleHide() {
}
//location.pathname 属性返回url的路径名如果存在 //替换为/
function getLocationPathName() {
return window.location.pathname.replace("\//","\/");
}
//自定义列设置事件
function customColumnClick(){
var submit = function(v,h,f) {
var abVisCols = [true];
$(".customColumnList input[type='checkbox']").each(function(){
abVisCols[$(this).val()] = $(this).prop("checked");
});
var key = getLocationPathName()+"_visCols";
Cookies.set(key,JSON.stringify(abVisCols),{expires:7});
customColumnInit();
return true;
}
var html = "<div class='customColumnList'>";
$(".table tr th").each(function(colIndex,obj){
if(colIndex==0) { //第一列th含 checkbox ,结束本次循环, 下标从1开始反之0开始
var ckVal = $(this).find("input[type='checkbox']").val();
if(typeof(ckVal) != "undefined") {
return true;
}
}
var checked = ($(this).is(":visible") ? "checked='checked'":"");
var ckbox_html = "<input type='checkbox' "+checked+" value='"+colIndex+"'/>";
html+="<div class='col-md-6'><label>"+ckbox_html+" "+$(this).html()+"</label></div>";
})
html +="</div>";
$.jBox(html,{title:"Custom Columns",submit:submit});
}
//自定义列初始化先取cookie 后取table tr th
function customColumnInit() {
var key = getLocationPathName()+"_visCols";
var abVisCols = Cookies.get(key);
if(abVisCols != null && abVisCols.length > 0) {
abVisCols = $.parseJSON(abVisCols);
$(abVisCols).each(function(indexCol,col){
if(col) {
//选中则显示
showColumn(indexCol);
}else {
hideColumn(indexCol);
}
})
}else {
$(".table tr th").each(function(){
var indexCol = $(this).index();
if($(this).attr("isVisible")=="false") {
hideColumn(indexCol);
}else {
//选中则显示
showColumn(indexCol);
}
});
}
}
//隐藏索引列
function hideColumn(index) {
$(".table tr").each(function() {
$(this).find("th:eq(" + index + ")").hide();
$(this).find("td:eq(" + index + ")").hide();
})
}
//显示索引列
function showColumn(index) {
$(".table tr").each(function() {
$(this).find("th:eq(" + index + ")").show();
$(this).find("td:eq(" + index + ")").show();
})
}