数据表:如何在使用DrawCallBack后的角度编译表格HTML时,如何获取分页? [英] Datatables : How to get pagination working when table HTML is compiled with Angular after drawCallBack?

查看:224
本文介绍了数据表:如何在使用DrawCallBack后的角度编译表格HTML时,如何获取分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的drawCallBack函数:

This is my drawCallBack function :

"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调用返回的新数据刷新。

This is working fine when data table is loaded, but upon clicking on another page (e.g. 2nd page), the table HTML is not getting refreshed with the new data returned from AJAX call.

似乎有角度正在编译它从 $(#example_table)。html();

It seems like angular is compiling old HTML which it gets from $("#example_table").html();.

渲染完成(所以我可以重新编译新的,新鲜渲染的HTML)?

What's the way to capture the event when the rendering is complete (so that I can re-compile new, freshly rendered HTML)?

推荐答案

更改选择器,身体解决了这个问题。

var selector = $(#exampleTable tbody);

Changing the selector, targeting the table body solves this problem. var selector = $("#exampleTable tbody");

这篇关于数据表:如何在使用DrawCallBack后的角度编译表格HTML时,如何获取分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆