简体   繁体   English

当ajax请求完成时,不会调整列的大小

[英]Columns are not resized when ajax request is complete

I'm using an Ajax data source with my DataTables grid, but the columns are not auto sized and the horizontal scrolling is not working too. 我正在使用带有DataTables网格的Ajax数据源,但列不是自动调整大小的,而且水平滚动也不起作用。

How do I fix this? 我该如何解决?

I'm using this code: 我正在使用此代码:

self.dataTableGrid = self.grid.dataTable({
    'bServerSide': true,
    'sAjaxSource': self.grid.data('loadaction'),
    'sPaginationType': 'bootstrap',
    'bProcessing': true,
    'sScrollX': "100%",
    'sScrollXInner': "110%",
    'bScrollCollapse': true,
    'oLanguage': {
        'sUrl': self.grid.data('gridtranslation')
    },
    'bAutoWidth': true,
    'bDeferRender': true,
    'fnInitComplete': function() {
        this.fnAdjustColumnSizing(true);
    },
    'aoColumns': [{
                'sName': 'Name',
                'mData': 'Name',
                'bSearchable': true,
                'bSortable': true,
                'sWidth': '300px'
            },
            {
                'sName': 'Address',
                'mData': 'Address',
                'bSearchable': false,
                'sWidth': '300px',
                'bSortable': true,
                'mRender': function (data, type, full) {
                    return data + ', ' + full.Number.toString();
                }
            },
            {
                'sName': 'City',
                'mData': 'City',
                'bSearchable': false,
                'bSortable': true
            }]
});

Problem solved by setting sScrollXInner to a higher value (like 150%) and bAutoWidth to false. 通过将sScrollXInner设置为更高的值(如150%)并将bAutoWidth设置为false来解决问题。 Also, the fnInitComplete is not necessary. 此外,fnInitComplete不是必需的。

Here is the final code: 这是最终的代码:

self.dataTableGrid = self.grid.dataTable({
'bServerSide': true,
'sAjaxSource': self.grid.data('loadaction'),
'sPaginationType': 'bootstrap',
'bProcessing': true,
'sScrollX': "100%",
'sScrollXInner': "150%",
'bScrollCollapse': true,
'oLanguage': {
    'sUrl': self.grid.data('gridtranslation')
},
'bAutoWidth': false,
'bDeferRender': true,
'aoColumns': [{
            'sName': 'Name',
            'mData': 'Name',
            'bSearchable': true,
            'bSortable': true,
            'sWidth': '300px'
        },
        {
            'sName': 'Address',
            'mData': 'Address',
            'bSearchable': false,
            'sWidth': '300px',
            'bSortable': true,
            'mRender': function (data, type, full) {
                return data + ', ' + full.Number.toString();
            }
        },
        {
            'sName': 'City',
            'mData': 'City',
            'bSearchable': false,
            'bSortable': true
        }]

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM