jquery tablesorter限制过滤器的长度

时间:2017-03-10 17:43:37

标签: jquery tablesorter

我正在使用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();

1 个答案:

答案 0 :(得分:0)

试试这个(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类时仅显示可用选项。

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

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