0

I've a paginated table (primeface datatable), changing page, content is loaded via ajax. On complete event of the ajax request, data-ng-click attribute is added to all rows.

Here is how tr is rendered

<tr data-ng-click="init(1,2)" class="ui-widget-content ui-datatable-even ui-datatable-selectable ui-state-highlight" aria-selected="true" role="row" data-rk="1-2" data-ri="0" >

Here is how I add data-ng-click attribute to tr, and how to angular app and controller are defined:

angularizeDataTable();

function angularizeDataTable(){
    $("[data-rk]").each(function(i, val){
        idt = $(this).attr("data-rk").split("-")[0];
        idv = $(this).attr("data-rk").split("-")[1];
        $(this).attr("data-ng-click", "init("+idt+","+idv+")");
    })
    .promise().done(function(){
        app = angular.module('myapp', []);
        app.controller('MainController', function($scope, $http){
            $scope.init = function(idt,idv){
                alert(idt+","+idv);
            };
        });
    });
}

angularizeDataTable function is executed on page load and every time i change page

<p:ajax event="page" oncomplete="angularizeDataTable()" />

But after page event fire, data-ng-click is ignored, why?

longy
  • 97
  • 1
  • 10
  • Why are you creating a table with jQuery. Maybe read this: http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background – New Dev Dec 24 '14 at 20:17
  • I'm trying to create master/detail view combining the power of primefaces datatable and angularjs. I cannot modify datatable. In the end I opted to handle them separately. However thanks for the reply. – longy Dec 28 '14 at 12:55

1 Answers1

0

I think you need to run the $compile service on the element to get the ng-click working

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – soyuka Jan 06 '15 at 16:59
  • When adding some new attributes like hte ngClick directive in the DOM after angular has linked the directives, the $compile angular service must be called to bind the service to the DOM element as it has changes. – Heroic Tomorrow Jan 06 '15 at 17:02