search

Home  >  Q&A  >  body text

angular.js - datatable 重新渲染 rerender 能不能不重现请求ajax 数据

当配置了 ajax 后,我每次执行rerender后都重新请求数据,导致本来时第三页的,但重新渲染了后变回第一页了,有办法只重新渲染不重新请求ajax数据吗,或重新请求时仍然是第三页

我想大声告诉你我想大声告诉你2750 days ago755

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-15 17:11:55

    I use datatable more, combined with the information you provided

    Refresh the data of the current page

    ajax retrieves the data of the current page number

    var dt = $('#datatable').DataTable({
        ...
    });
    dt.ajax.reload(null, false); //记得这两个参数

    F5 refresh page

    After F5, the current page number is still maintained. This requires a little skill. Use localhost.hash to save page number, sorting and other data

    Conditions:

    1. Convenient operation tool for loading Hash: https://github.com/cowboy/jquery-bbq

    2. Follow this

    var _config = {
        displayStart: 0, 
        pageLength: 10,
        order: [],
        drawCallback: function( settings ) {
            //绘制好之后,将状态写到Hash上面,翻页,排序的时候也会保持状态
            var config = {
                displayStart: settings._iDisplayStart,
                pageLength: settings._iDisplayLength,
                search: {search: settings.oPreviousSearch.sSearch},
                order: []
            };
            settings.aLastSort.forEach(function(v){
                config.order.push([v.col, v.dir]);
            });
            $.bbq.pushState(config);
        },
        .....
    };
    var config = $.bbq.getState();
    config = $.extend(true, _config, config);
    
    var dt = $('#datatable').DataTable(config);
    
    
    

    reply
    0
  • Cancelreply