我正在尝试找出此脚本在某些设备上失败的原因。它在 Firefox、Chrome 甚至 IE 浏览器中都能正常工作,但在 Safari IOS 中却不行。
我在这里使用 iPad 通过 JS Fiddle 测试结果: Example »
HTML 取自 UAT 网站,因此有点粗,但我已将其略微缩小。以及从最初的 1000 行中删除的脚本。
用于列计算的 JavaScript:
$.fn.manageColumns = function () {
function isVisible () {
return $(this).css("display") !== "none";
}
try {
var $that = $(this);
var $parent = $that.closest("form");
var data = $parent.data("state");
if (! $.isPlainObject(data)) { data = $parent.attr("data-state"); }
if (! $.isPlainObject(data)) { throw new TypeError("data-state not an object"); }
console.log(typeof data);
if ($.isPlainObject(data)) {
var groups = data.groups;
var groupString = "";
$.each(groups, function (key, value) {
groupString += "[data-column-group=\"" + value + "\"],";
});
if (groupString.length) {
groupString = groupString.slice(0, -1);
}
console.log(groupString);
var $visible = $that.find(groupString).not(".column-vis");
var $hidden = $that.find("[data-column-group]").not(".column-vis").not($visible);
var $all = $that.find("[data-column-all]").not(".column-vis");
$all.hide();
$visible.show();
if ($parent.width() < $that.width()) {
console.log("Will hide columns to fit screen size");
var maxIterations = 100;
var minGroups = 1;
var group = Number.MAX_VALUE;
for ( ; ($parent.width() < $that.width()) && (maxIterations > 0) &&
(group > minGroups); --maxIterations) {
var $nextElem = $that.find("col").filter(isVisible).last();
group = parseInt($nextElem.data("column-group"));
$that.find("[data-column-group=\"" + group + "\"]").not(".column-vis").hide();
}
var span = 0;
$that.find("col").each(function () {
var $vCol = $(this);
if ($vCol.isVisible()) {
var columnSpan = parseInt($vCol.attr("span"));
if (columnSpan <= 0) {
columnSpan = 1;
}
span += parseInt(columnSpan);
}
});
$all.attr("colspan", span).show();
}
else {
console.log("Don't need to hide columns");
$all.show();
$hidden.hide();
$visible.show();
}
}
}
catch (e) {
console.log(e.message);
}
};
HTML:
<body><div class="test-widget test-table-container"><div class="test-widget-bg"></div><span class="test-icon icon-setup test-icon-corner"></span><p class="test-widget-title">Schedule</p><p class="test-widget-info"></p><div><div><div class="test-table-gutter"><div class="test-table"><form action="javascript:;" autocomplete="off" data-feature-id="54188" data-source-id="a586120c-e3df-44a4-ab21-ef59c9a9f111" data-target-id="56836" data-widget-id="748" enctype="multipart/form-data" method="post"><table class="test-data-table table table-bordered table-hover table-column-control table-active"><colgroup><col class="row-status-color" span="1" /><col class="select-all-rows" span="1" /><col data-column-group="1" span="1" /><col data-column-group="2" span="1" /><col data-column-group="3" span="1" /><col data-column-group="4" span="1" /><col data-column-group="5" span="6" /><col data-column-group="6" span="5" /><col data-column-group="7" span="3" /><col data-column-group="8" span="7" /><col data-column-group="9" span="5" /></colgroup><thead><tr><th colspan="32" data-column-all="all"><div class="col-xs-12 col-sm-9"><div class="test-table-filters test-table-match"><div><div class="test-table-filter" data-filter-id="55f025e2-c68e-4210-a174-e34395a3e5dc"></div></div></div></div><div class="col-xs-12 col-sm-3"><div class="test-table-control test-table-match"><div class="test-auto-key test-control-select"></div><div class="multiselect test-control-select"><div class="select-box"><ul class="form-control"><li>Columns</li></ul><div class="checkboxes-over-select"></div></div><div class="checkboxes"><label for="2fba68e2-7d23-46bb-b340-075ef549b51f"><input checked="checked" class="column-vis" data-column-group="1" id="2fba68e2-7d23-46bb-b340-075ef549b51f" type="checkbox" />Name</label><label for="85f5631d-4fa2-4708-9001-075d67104ec6"><input checked="checked" class="column-vis" data-column-group="2" id="85f5631d-4fa2-4708-9001-075d67104ec6" type="checkbox" />Zone</label><label for="0a1e4226-4402-47ec-ae98-426ee767a4ed"><input checked="checked" class="column-vis" data-column-group="3" id="0a1e4226-4402-47ec-ae98-426ee767a4ed" type="checkbox" />Status</label><label for="47ebdbde-3f49-4d40-a855-d27b82865c50"><input checked="checked" class="column-vis" data-column-group="4" id="47ebdbde-3f49-4d40-a855-d27b82865c50" type="checkbox" />Roamable</label><label for="f70ceb61-1b6f-41cd-b251-5735dc7bd6b6"><input checked="checked" class="column-vis" data-column-group="5" id="f70ceb61-1b6f-41cd-b251-5735dc7bd6b6" type="checkbox" />Schedule</label><label for="2ef942c6-af71-4c00-ac95-0d87d443b8fd"><input checked="checked" class="column-vis" data-column-group="6" id="2ef942c6-af71-4c00-ac95-0d87d443b8fd" type="checkbox" />Authentication</label><label for="8ff2a2c5-5c1f-4ff7-bb99-95adfa20fe04"><input checked="checked" class="column-vis" data-column-group="7" id="8ff2a2c5-5c1f-4ff7-bb99-95adfa20fe04" type="checkbox" />Device</label><label for="babda357-ae2e-41fe-8434-4bf43a969c6d"><input checked="checked" class="column-vis" data-column-group="8" id="babda357-ae2e-41fe-8434-4bf43a969c6d" type="checkbox" />Vanity</label><label for="ca231149-ec2b-4235-b797-5616461190d7"><input checked="checked" class="column-vis" data-column-group="9" id="ca231149-ec2b-4235-b797-5616461190d7" type="checkbox" />Traffic</label></div></div><div class="test-row-count test-control-select"></div></div></div><div class="col-xs-12 test-attached-filters"></div></th></tr><tr class="column-grouping"><th class="row-status-color"></th><th></th><th colspan="1" data-column-group="1"></th><th colspan="1" data-column-group="2"></th><th colspan="1" data-column-group="3"></th><th colspan="1" data-column-group="4"></th><th colspan="6" data-column-group="5" style="background:rgb(109, 56, 107); color:#FFF;">Schedule</th><th colspan="5" data-column-group="6" style="background:rgb(204, 155, 56); color:#FFF;">Authentication</th><th colspan="3" data-column-group="7" style="background:rgb(192, 105, 119); color:#FFF;">Device</th><th colspan="7" data-column-group="8" style="background:rgb(150, 150, 116); color:#FFF;">Vanity</th><th class="last" colspan="5" data-column-group="9" style="background:rgb(138, 126, 149); color:#FFF;">Traffic</th></tr><tr class="column-headers"><th class="row-status-color"></th><th class="select-all-rows"><input class="check-all-rows" type="checkbox" /></th><th class="column-sortable check-active" data-column-group="1" data-source-id="49421">Name</th><th class="column-sortable check-active" data-column-group="2" data-source-id="56844">Zone</th><th class="column-sortable check-active" data-column-group="3" data-source-id="49426">Status</th><th class="column-sortable check-active" data-column-group="4" data-source-id="49427">Roamable</th><th class="column-sortable check-active" data-column-group="5" data-source-id="56841">Recurrence</th><th class="column-sortable check-active" data-column-group="5" data-source-id="56842">Limit</th><th class="column-sortable check-active" data-column-group="5" data-direction="ascending" data-source-id="49424">From</th><th class="column-sortable check-active" data-column-group="5" data-source-id="49425">Until</th><th class="column-sortable check-active" data-column-group="5" data-source-id="56852">reparation Period</th><th class="column-sortable check-active" data-column-group="5" data-source-id="56853">Cleanup Period</th><th class="column-sortable check-active" data-column-group="6" data-source-id="56855">Default Access Code</th><th class="column-sortable check-active" data-column-group="6" data-source-id="56856">Bandwidth</th><th class="column-sortable check-active" data-column-group="6" data-source-id="56857">riority Access Code</th><th class="column-sortable check-active" data-column-group="6" data-source-id="56858">Bandwidth</th><th class="column-sortable check-active" data-column-group="6" data-source-id="49431">Alert Threshold</th><th class="column-sortable check-active" data-column-group="7" data-source-id="49432">Limit</th><th class="column-sortable check-active" data-column-group="7" data-source-id="49434">Alert Threshold</th><th class="column-sortable check-active" data-column-group="7" data-source-id="49433">Currently Active</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56849">SSID</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56851">SSID Grace Period</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56850">Hide</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56846">Encryption</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56847">rotocol</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56848">Key</th><th class="column-sortable check-active" data-column-group="8" data-source-id="56845">VLAN</th><th class="column-sortable check-active" data-column-group="9" data-source-id="49438">Upload</th><th class="column-sortable check-active" data-column-group="9" data-source-id="49440">ackets</th><th class="column-sortable check-active" data-column-group="9" data-source-id="49439">Download</th><th class="column-sortable check-active" data-column-group="9" data-source-id="49441">ackets</th><th class="column-sortable check-active" data-column-group="9" data-source-id="49437">Logging</th></tr></thead><tbody><tr class="data-row" data-anch-target="28"><td class="row-status-color" style="background: rgb(109, 56, 107)"></td><td class="selecting"><input class="check" type="checkbox" value="28" /></td><td class="expand bold" data-column-group="1">Test</td><td class="expand" data-column-group="2">Guest</td><td class="expand" data-column-group="3">Active</td><td class="expand" data-column-group="4"><span class="icon-no"></span></td><td class="expand" data-column-group="5">Once</td><td class="expand" data-column-group="5">0</td><td class="expand" data-column-group="5">2016-03-08 00:00:00</td><td class="expand" data-column-group="5">2016-03-09 18:00:00</td><td class="expand" data-column-group="5">01:00:00</td><td class="expand" data-column-group="5">01:00:00</td><td class="expand" data-column-group="6">standard</td><td class="expand" data-column-group="6">Regular Speed Conference</td><td class="expand" data-column-group="6">best</td><td class="expand" data-column-group="6">Complimentary Low Speed (Lobby)</td><td class="expand" data-column-group="6">90</td><td class="expand" data-column-group="7">3</td><td class="expand" data-column-group="7">70</td><td class="expand" data-column-group="7">0</td><td class="expand" data-column-group="8">UAT_Test_SSID</td><td class="expand" data-column-group="8">00:30:00</td><td class="expand" data-column-group="8"><span class="icon-no"></span></td><td class="expand" data-column-group="8">None</td><td class="expand" data-column-group="8">WPA_CCMP</td><td class="expand" data-column-group="8"></td><td class="expand" data-column-group="8">UAT_CONFERENCE</td><td class="expand" data-column-group="9">0</td><td class="expand" data-column-group="9">0</td><td class="expand" data-column-group="9">0</td><td class="expand" data-column-group="9">0</td><td class="expand" data-column-group="9"><span class="icon-no"></span></td></tr></tbody></table></form></div></div></div></div></div></body>
如果您在 JS Fiddle 示例中展开窗口,您将看到基于屏幕宽度隐藏和显示的列。
我知道这有点粗糙,但我们将不胜感激。
bootstrap 将 100% 分配为表格宽度和表格最大宽度,因此在 Safari 中,您的 if ($parent.width() < $that.width())
不起作用,因为
是表格,与窗口一样大,而不是更大。
只需添加
.table {
width: intrinsic;
max-width:intrinsic;
}
到你的css,你就完成了
关于javascript - 基于宽度计算的表格列显示和隐藏在 Safari IOS 设备中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35918324/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |