【问题标题】:Datatables : How to get pagination working when table HTML is compiled with Angular after drawCallBack?Datatables:在drawCallBack之后用Angular编译表格HTML时如何使分页工作?
【发布时间】:2017-07-27 16:33:47
【问题描述】:

这是我的 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。

渲染完成时捕获事件的方法是什么(以便我可以重新编译新的、新渲染的 HTML)?

【问题讨论】:

    标签: jquery html angularjs datatable datatables


    【解决方案1】:

    更改选择器,定位表体解决了这个问题。 var selector = $("#exampleTable tbody");

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-01
      • 2013-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      相关资源
      最近更新 更多