如何为列设置 Column-Toggle Table Widget 的默认值? [英] How to set default value of Column-Toggle Table Widget for a column?

查看:30
本文介绍了如何为列设置 Column-Toggle Table Widget 的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩弄 jQuery Mobile 的 Table Widget.有没有办法可以通过此小部件从表头名称设置列的显示隐藏状态?如果没有这样的方法,那么解决此类问题的最佳方法是什么?

解决方案

jQM 没有为此提供 out-of-the-box 解决方案,因此您必须通过 JS 来完成.column toggle 弹出窗口继承了 tableid 后跟 -popup.您需要在 tablecreate 事件触发以更改 checkbox(es) 属性时定位它.

请注意,只有带有 data-prioritythead 元素会被添加到 column toggle 弹出窗口中.此外,您需要通过 index 使用 .eq() 方法或 :eq()<来定位 checkbox(es)/code> 选择器.

$(document).on("pagebeforecreate", "#pageID", function () {$("#tableID").on("tablecreate", function () {$("#tableID-popup [type=checkbox]:eq(1)")/* 第二个复选框 */.prop("checked", false)/* 取消选中 */.checkboxradio("refresh")/* 刷新 UI */.trigger("改变");/* 触发更改更新表 */});});

<块引用>

演示

I have been toying around with the Table Widget for jQuery Mobile. Is there a way I can set the show-hide status of a column from its table header name via this widget? If there is no such way what will be the best solution for such a problem?

解决方案

jQM doesn't offer an out-of-the-box solution for this, therefore, you have to do it through JS. The column toggle popup inherits table's id followed by -popup. You need to target it when tablecreate event fires to change checkbox(es) property.

Note that only thead elements with data-priority will be added to column toggle popup. Moreover, you will need to target checkbox(es) by their index using .eq() method or :eq() selector.

$(document).on("pagebeforecreate", "#pageID", function () {
   $("#tableID").on("tablecreate", function () {
       $("#tableID-popup [type=checkbox]:eq(1)") /* second checkbox */
           .prop("checked", false)            /* uncheck it */
           .checkboxradio("refresh")          /* refresh UI */
           .trigger("change");                /* trigger change to update table */
   });
});

Demo

这篇关于如何为列设置 Column-Toggle Table Widget 的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆