jQuery手机桌面设置默认视图
问题描述:
有谁知道如何设置jQuery移动列切换表,以便当用户加载页面时,只有某些列默认可见?例如,列1-6可见,但列7不可见,必须使用列选择器按钮打开。jQuery手机桌面设置默认视图
这里是我的project example
<thead>
<tr>
<th data-priority="1">Date</th>
<th>Client</th>
<th data-priority="2">Dates and Times Needed</th>
<th data-priority="3">Caregiver In Mind</th>
<th data-priority="4">Notes</th>
<th data-priority="5">Comunication</th>
<th data-priority="6">Unable Reason</th> <!-- Want this column to be hidden by default -->
</tr>
</thead>
答
此功能没有内置到窗口小部件,所以你必须自己编写它。
这里有一种方法:
它扩展了Omars回答这里:How to set default value of Column-Toggle Table Widget for a column?将属性添加到您想要隐藏的列(S)。
在表<thead>
中为首先应该隐藏的列添加新的数据属性。在我的例子data-hiddendefault="true"
:
<thead>
<tr>
<th data-priority="2">Date</th>
<th>Client</th>
<th data-priority="3">Dates and Times Needed</th>
<th data-priority="1">Caregiver In Mind</th>
<th data-priority="3">Notes</th>
<th data-priority="3">Comunication</th>
<th data-priority="3" data-hiddendefault="true">Unable Reason</th>
</tr>
</thead>
然后添加脚本到tablecreate
事件。我们首先获得列切换弹出窗口的ID(表ID +'-popup')。然后遍历所有列标题并找到具有数据优先级的列标题,因为这些列出现在列切换弹出窗口中。现在,请查看是否隐藏列的新属性是存在的,如果是,设置它的复选框,在弹出来加以控制,刷新复选框控件,并触发复选框的更改事件:
$('[data-mode="columntoggle"]').on('tablecreate', function(event, ui) {
var id = this.id + "-popup";
var $cols = $(this).find("thead th");
var idx = 0;
$cols.each(function(index){
if ($(this).jqmData("priority")){
if ($(this).jqmData("hiddendefault") == true) {
$("#" + id + " [type=checkbox]:eq(" + idx + ")").prop("checked", false).checkboxradio("refresh").trigger("change");
}
idx++;
}
});
});
这里是你的更新FIDDLE
在这里我们去,隐藏的列http://jsfiddle.net/q1616oa1/1/ – caramba 2014-10-20 15:03:50
样的作品,但该列不能在你的例子重新打开。我希望用户能够通过在列选择器中将其打开来再次使该列可见。 – Austin 2014-10-20 15:07:55