Jim Lobo Jim Lobo - 1 month ago 10
jQuery Question

How to open JQuery Datatable Render column which is URL in new window using return

I am using Jquery Datatable1.10.12. using AJAX & JSON. I have column names which are URLs . When I click the column names I can't open the URLs in a new window in web browsers. It's opening in the same window. Any Advise would be great on How to get it done.

<script type="text/javascript">
$(document).ready(function () {
$.ajax({
// asmx service to retrive the data from server side
url: '<%= ResolveUrl("FirmDetailService.asmx/GetFirmDetails")%>',
method: 'post',
dataType: 'json',
success: function (data) {
$('#example').DataTable({
searchHighlight: true,
lengthChange: false,
language: {
searchPlaceholder: "Search records"},
data: data,
'columns': [
{ 'data':'PID', 'visible':false},
{ 'data' : 'PersonName',
'render': function (data, type, row, meta) {
var idp = row['PID'];
return '<a href="FirmsDeatils.aspx?id=' + idp + '">' + data + '</a>';
}
},
{ 'data': 'CID', 'visible':false },
{ 'data': 'CompanyName',
'render': function (data, type, row, meta) {
var idc = row['CID'];
return '<a href="FirmsDeatils.aspx?id=' + idc + '">' + data + '</a>';
}
},
{ 'data': 'City' },
{ 'data': 'Country' },
]
}
);
}
});
}
);
</script>

Answer

Add target="_blank" attribute for <a> elements.

For example:

return '<a target="_blank" href="FirmsDeatils.aspx?id=' + idp + '">' + data + '</a>';
Comments