processAjaxOnInit:设置为" false"但仍然会调用Ajax

时间:2016-01-24 05:19:28

标签: tablesorter

我正在使用PHP预加载我的表,然后在我的配置中使用processAjaxOnInit:false。发生的事情是仍然调用我的Ajax网址,而不是向表中附加行,它会清除那里的行。我假设它仍在调用以获取总行数。我可以在页面加载时设置它并完全绕过调用Ajax URL吗?

由于

.tablesorterPager({

  container: $(".pager"),

  ajaxUrl : '/documents_table_data.php?page={page}&size={size}&{filterList:filter}&{sortList:column}',

  // use this option to manipulate and/or add additional parameters to the ajax url
  customAjaxUrl: function(table, url) {
    // manipulate the url string as you desire
    //url += '&archive=<?php echo $_GET[archive] ?>&wor=<?php echo $_GET[wor] ?>';

    // trigger a custom event; if you want
    $(table).trigger('changingUrl', url);
    // send the server the current page
    return url;
  },
  ajaxError: null,
  ajaxObject: {
    dataType: 'json'
  },
  ajaxProcessing: function(data){
    if (data && data.hasOwnProperty('rows')) {
      var r, row, c, d = data.rows,
      total = data.total_rows,
      headers = data.headers,
      rows = [],
      len = d.length;
      for ( r=0; r < len; r++ ) {
        row = [];
        for ( c in d[r] ) {
          if (typeof(c) === "string") {
            row.push(d[r][c]);
          }
        }
        // is there a way to do that here when it pushes the row onto the array
        // or perhaps there is another funtion you have implemented that will let me do that
        rows.push(row);
      }
      return [ total, rows, headers ];
    }
  },

  // Set this option to false if your table data is preloaded into the table, but you are still using ajax
  processAjaxOnInit: false,
  output: '{startRow} to {endRow} ({totalRows})',
  updateArrows: true,
  page: 0,
  size: 10,
  savePages: true,
  storageKey: 'tablesorter-pager',
  pageReset: 0,
  fixedHeight: false,
  removeRows: false,
  countChildRows: false,

  // css class names of pager arrows
  cssNext        : '.next',  // next page arrow
  cssPrev        : '.prev',  // previous page arrow
  cssFirst       : '.first', // go to first page arrow
  cssLast        : '.last',  // go to last page arrow
  cssGoto        : '.gotoPage', // page select dropdown - select dropdown that set the "page" option

  cssPageDisplay : '.pagedisplay', // location of where the "output" is displayed
  cssPageSize    : '.pagesize', // page size selector - select dropdown that sets the "size" option

  // class added to arrows when at the extremes; see the "updateArrows" option
  // (i.e. prev/first arrows are "disabled" when on the first page)
  cssDisabled    : 'disabled', // Note there is no period "." in front of this class name
  cssErrorRow    : 'tablesorter-errorRow' // error information row

});

1 个答案:

答案 0 :(得分:0)

我刚刚添加了一个名为initialRows的寻呼机选项(目前仅在主分支中可用)。如果processAjaxOnInitfalse并且设置了此选项,则不会对服务器进行初始ajax调用(demo):

$(function(){
  $('table').tablesorter({
    widgets: ['pager'],
    widgetOptions : {
      pager_processAjaxOnInit: false,
      pager_initialRows: {
        // these are both set to 50 initially
        // the server can return different values
        // and the output will update automatically
        total: 50,
        filtered: 50
      },
      // other ajax settings...
    }
  });
});