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.
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>';
}
}
]
@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);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With