Javascript 无法读取属性';oScroll&x27;未定义的jQuery数据表的数量

Javascript 无法读取属性';oScroll&x27;未定义的jQuery数据表的数量,javascript,jquery,jquery-ui,jquery-plugins,jquery-datatables,Javascript,Jquery,Jquery Ui,Jquery Plugins,Jquery Datatables,我正在使用datatables对从服务器加载的结果进行分页 当我导入jquery.dataTables.js和jquery.dataTables.css(1.10.2)时,浏览器控制台显示以下错误:无法读取未定义的属性“oScroll”。问题出在这一行: var scroll = settings.oScroll; 它涉及重新计算datatables列大小的函数: /** * This function will make DataTables recalculate the column

我正在使用datatables对从服务器加载的结果进行分页

当我导入jquery.dataTables.js和jquery.dataTables.css(1.10.2)时,浏览器控制台显示以下错误:无法读取未定义的属性“oScroll”。问题出在这一行:

 var scroll = settings.oScroll;
它涉及重新计算datatables列大小的函数:

/**
 * This function will make DataTables recalculate the column sizes, based on the data
 * contained in the table and the sizes applied to the columns (in the DOM, CSS or
 * through the sWidth parameter). This can be useful when the width of the table's
 * parent element changes (for example a window resize).
 *  @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
 *  @dtopt API
 *  @deprecated Since v1.10
 *
 *  @example
 *    $(document).ready(function() {
 *      var oTable = $('#example').dataTable( {
 *        "sScrollY": "200px",
 *        "bPaginate": false
 *      } );
 *
 *      $(window).bind('resize', function () {
 *        oTable.fnAdjustColumnSizing();
 *      } );
 *    } );
 */
this.fnAdjustColumnSizing = function ( bRedraw )
{
    var api = this.api( true ).columns.adjust();
    var settings = api.settings()[0];
    var scroll = settings.oScroll;

    if ( bRedraw === undefined || bRedraw ) {
        api.draw( false );
    }
    else if ( scroll.sX !== "" || scroll.sY !== "" ) {
        /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
        _fnScrollDraw( settings );
    }
};
有人知道这个问题吗


提前感谢。

这是另一个
dataTable()
vs
dataTable()
问题。如您所见,
fnastjustcolumnsize
已被弃用。更糟糕的是,它根本不适用于
DataTable()
-构造函数。解决方案,或者使用旧的dataTable构造函数实例化表:

var table = $('#example').dataTable({
或者,使用1.10.xAPI方法:

var table = $('#example').DataTable({
   "sScrollY": "200px",
   "bPaginate": false
});

$(window).bind('resize', function () {
   table.columns.adjust().draw(); 
});
演示您可以同时使用这两种方法进行试验->