繁体   English   中英

Datatables:在drawCallBack之后用Angular编译表HTML时,如何使分页工作?

[英]Datatables : How to get pagination working when table HTML is compiled with Angular after drawCallBack?

这是我的drawCallBack函数:

"fnDrawCallback": function( oSettings ) {
            console.log("dt redrawn");
            var selector = $("#example_table");
            console.log(selector);

            function recompileForAngular() {
                angular.element(document).injector().invoke(['$compile', function ($compile) {
                    // Create a scope.
                    var $scope = angular.element(document.body).scope();
                    // Specify what it is we'll be compiling.
                    var to_compile = $(selector).html();
                    // Compile the tag, retrieving the compiled output.
                    var $compiled = $compile(to_compile)($scope);
                    // Ensure the scope and been signalled to digest our data.
                    $scope.$digest();
                    // Replace the compiled output to the page.
                    $(selector).html($compiled);
                }]);
            }

            function init(recompile) {
                recompile();
            }

            init(recompileForAngular);
        },

加载数据表时,此方法工作正常,但是单击另一页(例如,第二页)时,表HTML不会被AJAX调用返回的新数据刷新。

似乎angular正在编译从$("#example_table").html();获取的旧HTML $("#example_table").html();

渲染完成后如何捕获事件(以便我可以重新编译新的,刚渲染的HTML)?

更改选择器(以表格主体为目标)可以解决此问题。 var selector = $("#exampleTable tbody");

暂无
暂无

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

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