【问题标题】:jquery tablesorter limit length of filterjquery tablesorter限制过滤器的长度
【发布时间】:2017-03-11 06:35:34
【问题描述】:

我使用的是 TableSorter 版本 2.28.1。我正在使用带有母版页的.net。我在我的 aspx Gridview 控件上设置了一个过滤器。我的客户希望我将过滤器的长度限制为 3 个字符。过滤器所在列中所有值的长度只有 3。

有没有办法限制用户在过滤框中输入的内容的长度?

我试过这个...

widgetOptions: {
group_forceColumn: [0],
group_enforceSort: true,
filter_onlyAvail: {
    1: function (e, n, f, i, $r, c, data) {

        return f.toString().substring(0, 3);
    }
}

}

但它似乎没有做任何事情。但是我确实读到我需要将“filter-select”类名放在标题中。我如何为 Gridview 做到这一点?现在,为了使这项工作与我的 Gridview 一起工作,我执行以下操作以获取表格中的“Thead”。

        $("#<% =gvContractors.ClientID %> tbody").before("<thead><tr></tr></thead>");
        $("#<% =gvContractors.ClientID %> thead tr").append($("#<% =gvContractors.ClientID %> th"));
        $("#<% =gvContractors.ClientID %> tbody tr:first").remove();

【问题讨论】:

    标签: jquery tablesorter


    【解决方案1】:

    试试这个 (demo):

    $(function() {
      $('#<% =gvContractors.ClientID %>').tablesorter({
        theme: 'blue',
        widgets: ['zebra', 'filter'],
        initialized: function(table) {
            $(table).find('.tablesorter-filter').attr('maxlength', '3');
        }
      });
    });
    

    filter_onlyAvail option只能设置为字符串;当filter-select 类添加到标题时,作为类名用于仅显示可用选项。

    要将选择添加到第二列(eq() 使用从零开始的索引),请尝试以下代码:

    $("#<% =gvContractors.ClientID %> thead .tablesorter-filter:eq(1)")
    

    【讨论】:

    • 我添加的一件事是 ".eq(1)" ,将限制限制为仅列“1”。 " 已初始化:函数 (table) { $(table).find('.tablesorter-filter').eq(1).attr('maxlength', '3'); },"
    猜你喜欢
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2015-05-19
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多