使用ajax的Tablesorter过滤器buildSelect无法正常工作

时间:2018-03-07 21:12:00

标签: jquery ajax select filter tablesorter

仅当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 ];
    }
  },

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

1 个答案:

答案 0 :(得分:0)

补充:

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

现在就像魅力......