获取 columntoggle table 的选定列

Get selected columns for a columntoggle table

我有一个 columntoggle table,里面有一些信息。 我想获取选定的列是什么,将这些值存储在数据库中,当用户重新登录时,使用这些值使 table 加载他之前选择的列。

有什么办法吗?

提前致谢

uilt-in 没有任何东西可以做到这一点。这是一种方法:

jQM 创建一个列切换弹出窗口,其中为每个分配了数据优先级的列配备了一个复选框。弹出窗口采用 table 的 ID 加上“-popup”,因此您可以使用此选择器访问复选框:

$("#myTableid-popup .ui-checkbox label");

勾选的项目 class .ui-checkbox-on,未勾选的项目 .ui-checkbox-off。因此你可以获得所有可见列的索引(indices):

var selIndex = [];
function SaveSelectedColumns(){
    selIndex = [];
    $("#myTable-popup .ui-checkbox label").each(function(idx){
        if ($(this).hasClass("ui-checkbox-on")){
            selIndex.push(idx);    
        }
    });
}

然后恢复可见列:

function LoadSavedColumns(){
    $("#myTable-popup .ui-checkbox label").each(function(idx){
        var vis = IsColVisible(idx);
        if ($(this).hasClass("ui-checkbox-on") && !vis){
            $(this).click();    
        }
         if ($(this).hasClass("ui-checkbox-off") && vis){
            $(this).click();    
        }
    });
}

function IsColVisible(idx){
    for (var i=0; i<selIndex.length; i++){
         if (selIndex[i] == idx) return true;   
    }
    return false;
}

Working DEMO