5

I'd to link a column of my data-table to a dynamic Angularjs view.

Table 1 :

ID | Name | Action 

1  | Jack | Edit

Edit should be a link to #/clients/1/edit

/clients/:id/edit (app.client_edit) is already created and it's working.

I'm trying the code below:

$scope.dataTableOpt = {
 "columnDefs": [
    {
       "targets": 0,
       "render": function ( data ) {
          return "<a ui-sref=\"app.client_view({id: $row[0]})\">Edit</a>";
       }
    }
 ],
 'ajax': 'http://localhost/admin/clients'
};

Given result:

Link1 = < a ui-sref="app.client_view({'id': '1'})">edit</ a>

Expected result:

Link2 = < a ui-sref="app.client_view({id: '1'})" class="ng-scope" href="#!/client/2">edit</ a>

When I put < a ui-sref="app.client_view({'id': '1'})">test< / a> on the page statically it's working but not sure why it doesn't work when it's dynamically generated.

Please advise.

2 Answers 2

9

my way:

DataTable set options:

"columnDefs": [
   {
      "targets": [0, 1],
      "render": function ( data, type, row ) {
         var href = $compile('<a ui-sref="stateName({id: ' + $stateParams.id + '})"></a>')($scope)[0].href;
         return '<a href="' + href + '">' + data + '</a>';
       }
    }
]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much abbas, i spent 2 days to find this solution and it worked like charm. Thank you so much.
1

@Abbas Moazzemi

If Use .withOption('createdRow' as below, you dont need to use $compile:

.withOption('createdRow', function(row) {
    // Recompiling so we can bind Angular directive to the DT
    $compile(angular.element(row).contents())($scope);
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.