ajax处理后数据表fnAdjustColumnSizing不起作用
我目前正在使用带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过这样做,
因为我不确定
this
是否指向表对象Have you tried doing
Because i'm not sure that
this
points to table object我通过在我的ajax查询的“成功”回调中使用一个函数找到了一个解决方案:
它的工作方式就像一个魅力,但我不知道为什么。有人可以解释一下吗?
I find a solution by using a function inside the "success" callback of my ajax query :
And it work like a charm but I don't know why. Someone can explain ?
我在 Internet Explorer 8(不是 Firefox)中遇到了类似的问题:我的标题与表体未对齐。
该表在显示后在“模态”对话框(twitter bootstrap)内初始化。
最后,为了使其与 Internet Explorer 8 配合使用,在创建表后,我进行了此调用:
这会刷新表,而不会进行另一个不必要的 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:
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