2016-01-25 61 views
2

我正在使用Ajax寻呼机,并且我有一些向我的数据库添加记录的代码。我想要做的是强制记录刷新。我试图使用$(“builders_table”)。trigger(“update”),但这不起作用。如果我更改页面或筛选记录,则返回更新的记录,但是我希望在数据库更改后立即强制刷新。如何强制更新Ajax数据

感谢

$('#builders_table') 
.tablesorter({ 
    theme: 'blue', 
    widthFixed: true, 
    cancelSelection: false, 
    sortLocaleCompare: true, // needed for accented characters in the data 
    sortList: [ [1,1] ], 
    widgets: ['zebra', 'filter'] 
}) 

.tablesorterPager({ 

    container: $('.pager'), 

    ajaxUrl : '/builder_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 += url_extras; 

     // 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')) { 
     return [ data.total_rows, $(data.rows) ]; 
    } 
    }, 

    // Set this option to false if your table data is preloaded into the table, but you are still using ajax 
    processAjaxOnInit: true, 
    initialRows: { 
    // these are both set to 100 in the ajaxProcessing 
    // the these settings only show up initially 
    total: 50, 
    filtered: 50 
    }, 
    output: '{startRow} to {endRow} ({totalRows})', 
    updateArrows: true, 
    page: 0, 
    size: 50, 
    savePages: false, 
    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 

}); 

回答

0

的寻呼机有一个内置的方法来强制命名为"pagerUpdate"更新:

可以强制更新如下:

$('table').trigger('pagerUpdate'); 

,或者,如果你想强制更新并更改页面

$('table').trigger('pagerUpdate', 3); // update and set to page 3 
+0

感谢Mottie。我非常感谢你给予的大力支持。 – phpmaven