【问题标题】:Tablesorter filter buildSelect with ajax does not work properly使用 ajax 的 Tablesorter 过滤器 buildSelect 无法正常工作
【发布时间】:2018-08-16 02:34:30
【问题描述】:

仅当 ajax 返回 filter_listbox 对象时,我才通过 ajaxProcessing 函数构建过滤器选择:

$.tablesorter.filter.buildSelect("table", key, data.filter_listbox[value], true);

  ajaxProcessing: function(data){
    if (data && data.hasOwnProperty('rows')) {
      var indx, r, row, c, d = data.rows,
      total = data.total_rows, // total number of rows (required)
      headers = data.headers, // array of header names (optional)
      headerXref = headers.join(',').replace(/\s+/g,'').split(','), // cross-reference to match JSON key within data (no spaces)
      rows = [], // all rows: array of arrays; each internal array has the table cell data for that row
      len = d.length; // len should match pager set size (c.size)
      // rows
      for ( r=0; r < len; r++ ) {
        row = []; // new row array
        for ( c in d[r] ) { // cells
          if (typeof(c) === "string") { // match the key with the header to get the proper column index
            indx = $.inArray( c, headerXref );
            if (indx >= 0) { // add each table cell data to row array
              if (indx == 0) row[indx] = '<input type="checkbox" value="'+d[r][c]+'" />'; // input in first column
              else row[indx] = d[r][c];
            }
          }
        }
        rows.push(row); // add new row array to rows array
      }

      // Select list on filter in column with index 3
      if (typeof data.filter_listbox !== 'undefined'){
        $.each(headers, function(key, value) {
            //alert(value+" "+data.filter_listbox[value]);
            $.tablesorter.filter.buildSelect( "table", key, data.filter_listbox[value], true );
        });
      }

      // in version 2.10, you can optionally return $(rows) a set of table rows within a jQuery object
      // return [ total, rows, headers ]; // Also change headers
      return [ total, rows ];
    }
  },

Selectlist 构建得很好,但是如果我从 select 中选择一个选项,则不会在选择列表中选择选项。 Ajax 完美地返回数据,但是如果我单击屏幕上的任何位置,表格就会更新,就像我选择具有空值的选项并且选择列表被破坏一样。有人可以帮我阻止此更新并在选择列表中显示正确选择的选项吗?

【问题讨论】:

    标签: jquery ajax select filter tablesorter


    【解决方案1】:

    添加:

      filter_selectSource : {
        ".filter-select" : function() { return null; }
      },  
    

    现在就像一个魅力......

    【讨论】:

      猜你喜欢
      • 2013-09-15
      • 1970-01-01
      • 2015-02-14
      • 2013-08-16
      • 2012-11-16
      • 2011-04-06
      相关资源
      最近更新 更多