简体   繁体   English

angularjs中的自定义数据表信息

[英]Custom datatable info in angularjs

I am using angular and datatables together. 我使用的角度数据表一起。 One of my requirement is to customize the table info that shows the number of entries. 我的要求之一是定制显示条目数的表信息。 It is just not a text update which I could do using the language configuration of datatable, but I need to move it to a div outside the table. 这不是文本更新,我可以使用数据表的语言配置来完成,但是我需要将其移动到表外的div中。

I see this on the forum, but not sure how to do it in angularjs. 我在论坛上看到了这一点,但不确定如何在angularjs中做到这一点。 This is for pagination, but still I can use this for .dataTables_info . 这是用于分页,但是我仍然可以将其用于.dataTables_info

Pagination control outside datatable 分页控制外部数据表

 $(document).ready(function() {
     $("#example").dataTable(); 
     $("#NewPaginationContainer").append($(".dataTables_paginate"));
 });

As "Mr White" points out, you are asking for problems if you are using angularjs and dataTables the "jQuery way" in the same project. 正如“怀特先生”所指出的,如果您在同一项目中以“ jQuery方式”使用angularjs和dataTables,则您正在询问问题。 Though it is possible, you will face race issues and broken functionality as soon as you try to use dataTables more advanced features such as column rendering. 尽管可能,但是当您尝试使用dataTables更高级的功能(例如列渲染)时,您将面临种族问题和功能失效。 You should really consider using Angular dataTables , the angular directives for jQuery dataTables. 您应该真正考虑使用Angular dataTables ,即jQuery dataTables的angular指令。

Then this said, even though you are using jQuery dataTables with or without directives, you would need to do this in a $timeout , not in a callback such as initComplete() . 这就是说,即使您使用的是带或不带指令的jQuery dataTables,也需要在$timeout中而不是在诸如initComplete()的回调中进行。 That will sometimes fail since angular not nessecarily has finished its business when dataTables has. 这有时会失败,因为当dataTables完成时,Angular不一定会完成其业务。

Also, the solution you are referring to is not quite right. 另外,您所指的解决方案也不完全正确。 Have you checked the link in the answer? 您是否已查看答案中的链接? It leads to something completely else. 它带来了完全其他的东西。 The correct way would be : 正确的方法是:

$timeout(function() {
   $('.dataTables_info')  
    .detach()
    .appendTo('#NewPaginationContainer')
})   

demo -> http://plnkr.co/edit/VHYTFcng0A4w2ipJ7GX5?p=preview 演示-> http://plnkr.co/edit/VHYTFcng0A4w2ipJ7GX5?p=preview

The demo is using angular dataTables, so you can see the difference, but even though you are not using the directives, you should use the above approach. 该演示使用的是角度数据表,因此您可以看到差异,但是即使您没有使用指令,也应使用上述方法。

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

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