ajax处理后数据表fnAdjustColumnSizing不起作用

发布于 2024-12-23 13:23:41 字数 1008 浏览 0 评论 0原文

我目前正在使用带有 ajax 数据的数据表,我想调整列宽。 所以我找到了这个函数 fnAdjustColumnSizing 并且尝试使用它:

oTable = $('.datatable').dataTable( {
    "sScrollX": "100%",
    "sScrollXInner": "200%",
    "bScrollCollapse": true,
    "bDestroy" : true,
    "sAjaxSource": "xhr.php",
    "bFilter": false,
    "bSort": false,
    "bLengthChange": false,
    "bPaginate": false,
    "bInfo": false,
    "fnServerData": function ( sSource, aoData, fnCallback ) {
        $.ajax( {
            "dataType": 'json', 
            "type": "POST", 
            "url": "webservice.php", 
            "data": 'id=' + quotation_id + '&customer_id=' + id + '&action=true', 
            "success": function(msg){
                fnCallback(msg);
            }
        });
    },
    "fnInitComplete": function() {
        this.fnAdjustColumnSizing();
    }
});

该函数没有任何效果,但是如果我在另一个类似这样的事件中使用它:

$('#target').click(function() {
    oTable.fnAdjustColumnSizing();
});

它工作得很好,有什么想法吗?

I'm currently using datatables with ajax data and I want do adjust the column width.
So I found this function fnAdjustColumnSizing and I try to use it :

oTable = $('.datatable').dataTable( {
    "sScrollX": "100%",
    "sScrollXInner": "200%",
    "bScrollCollapse": true,
    "bDestroy" : true,
    "sAjaxSource": "xhr.php",
    "bFilter": false,
    "bSort": false,
    "bLengthChange": false,
    "bPaginate": false,
    "bInfo": false,
    "fnServerData": function ( sSource, aoData, fnCallback ) {
        $.ajax( {
            "dataType": 'json', 
            "type": "POST", 
            "url": "webservice.php", 
            "data": 'id=' + quotation_id + '&customer_id=' + id + '&action=true', 
            "success": function(msg){
                fnCallback(msg);
            }
        });
    },
    "fnInitComplete": function() {
        this.fnAdjustColumnSizing();
    }
});

The function haven't any effect but if I use it inside another event such like this :

$('#target').click(function() {
    oTable.fnAdjustColumnSizing();
});

It work well, any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

唠甜嗑 2024-12-30 13:23:42

您是否尝试过这样做,

"fnInitComplete": function() {
    oTable.fnAdjustColumnSizing();
}

因为我不确定 this 是否指向表对象

Have you tried doing

"fnInitComplete": function() {
    oTable.fnAdjustColumnSizing();
}

Because i'm not sure that this points to table object

冷情妓 2024-12-30 13:23:42

我通过在我的ajax查询的“成功”回调中使用一个函数找到了一个解决方案:

$.ajax( {
    "dataType": 'json', 
"type": "POST", 
"url": "webservice.php", 
"data": 'edit_quotation=true&action=true' + data, 
"success": function(msg){
    fnCallback(msg);
    $('.overlay').hide();
    adjustTable();
}
});

function adjustTable(){
    oTable.fnAdjustColumnSizing();
}

它的工作方式就像一个魅力,但我不知道为什么。有人可以解释一下吗?

I find a solution by using a function inside the "success" callback of my ajax query :

$.ajax( {
    "dataType": 'json', 
"type": "POST", 
"url": "webservice.php", 
"data": 'edit_quotation=true&action=true' + data, 
"success": function(msg){
    fnCallback(msg);
    $('.overlay').hide();
    adjustTable();
}
});

function adjustTable(){
    oTable.fnAdjustColumnSizing();
}

And it work like a charm but I don't know why. Someone can explain ?

琴流音 2024-12-30 13:23:42

我在 Internet Explorer 8(不是 Firefox)中遇到了类似的问题:我的标题与表体未对齐。

该表在显示后在“模态”对话框(twitter bootstrap)内初始化。
最后,为了使其与 Internet Explorer 8 配合使用,在创建表后,我进行了此调用:

var t = setTimeout(function () { myTableObject.fnAdjustColumnSizing(false);}, 300);

这会刷新表,而不会进行另一个不必要的 Ajax 调用,但在执行此操作之前会等待 300 毫秒,以“让 Internet Explorer 完成其工作” '在重新调整之前。如果您设置较低的值(即 10 毫秒),则这不起作用。

我希望它有帮助,

罗杰

I had a similar problem in Internet Explorer 8 (not in Firefox): I was getting my headers unaligned with respect to the table body.

The table is initialized inside a 'modal' dialog (twitter bootstrap), AFTER it is shown.
Finally, to make it work with Internet Explorer 8, after creating the table I'm making this call:

var t = setTimeout(function () { myTableObject.fnAdjustColumnSizing(false);}, 300);

This refreshes the table without making another unnecessary Ajax call, but it waits 300 ms before doing it, to 'let internet explorer do its thing' before readjusting. If you set lower values i.e. 10 ms) this doesn't work.

I hope it helps,

Roger

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文