|
|
|
@ -1,11 +1,11 @@
|
|
|
|
|
/**
|
|
|
|
|
* This data rendering helper method can be useful when a hyperLink with custom
|
|
|
|
|
* text has to rendered. The data for the column is still fully searchable and sortable, based on the hyperLink value,
|
|
|
|
|
* anchorText has to rendered. The data for the column is still fully searchable and sortable, based on the hyperLink value,
|
|
|
|
|
* and sortable, based on the hyperLink value, but during display in webpage is rendered with custom placeholder
|
|
|
|
|
*
|
|
|
|
|
* It accepts four parameters:
|
|
|
|
|
*
|
|
|
|
|
* 1. 'text' - type string - (optional - default `Click Here`) - The custom placeholder to display
|
|
|
|
|
* 1. 'anchorText' - type string - (optional - default `Click Here`) - The custom placeholder to display
|
|
|
|
|
* 2. 'location' - type string - (optional - default `newTab`)
|
|
|
|
|
* takes two values 'newTab' and 'popup'
|
|
|
|
|
* 3. 'width' - type integer - (optional - default `600`)
|
|
|
|
@ -35,7 +35,7 @@
|
|
|
|
|
* $('#example').DataTable( {
|
|
|
|
|
* columnDefs: [ {
|
|
|
|
|
* targets: 2,
|
|
|
|
|
* render: $.fn.dataTable.render.ellipsis( 'Download' )
|
|
|
|
|
* render: $.fn.dataTable.render.hyperLink( 'Download' )
|
|
|
|
|
* } ]
|
|
|
|
|
* } );
|
|
|
|
|
*
|
|
|
|
@ -45,7 +45,7 @@
|
|
|
|
|
* $('#example').DataTable( {
|
|
|
|
|
* columnDefs: [ {
|
|
|
|
|
* targets: 2,
|
|
|
|
|
* render: $.fn.dataTable.render.ellipsis( 'Download', 'popup' )
|
|
|
|
|
* render: $.fn.dataTable.render.hyperLink( 'Download', 'popup' )
|
|
|
|
|
* } ]
|
|
|
|
|
* } );
|
|
|
|
|
*
|
|
|
|
@ -55,59 +55,87 @@
|
|
|
|
|
* $('#example').DataTable( {
|
|
|
|
|
* columnDefs: [ {
|
|
|
|
|
* targets: 2,
|
|
|
|
|
* render: $.fn.dataTable.render.ellipsis( 'Download', 'popup' , 1000, 500)
|
|
|
|
|
* render: $.fn.dataTable.render.hyperLink( 'Download', 'popup' , 1000, 500)
|
|
|
|
|
* } ]
|
|
|
|
|
* } );
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
jQuery.fn.dataTable.render.hyperLink = function (text, location, width, height) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validateAndReturnDefaultIfFailed = function(item, defaultValue) {
|
|
|
|
|
|
|
|
|
|
if ( typeof item === 'number' ) {
|
|
|
|
|
jQuery.fn.dataTable.render.hyperLink = function (
|
|
|
|
|
anchorText,
|
|
|
|
|
location,
|
|
|
|
|
width,
|
|
|
|
|
height
|
|
|
|
|
) {
|
|
|
|
|
validateAndReturnDefaultIfFailed = function (item, defaultValue) {
|
|
|
|
|
if (typeof item === "number") {
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( typeof item === 'string' ) {
|
|
|
|
|
if (typeof item === "string") {
|
|
|
|
|
return parseInt(item) ? item : defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
text = text || 'Click Here';
|
|
|
|
|
location = location || 'newTab';
|
|
|
|
|
width = validateAndReturnDefaultIfFailed(width, '600');
|
|
|
|
|
height = validateAndReturnDefaultIfFailed(height, '400');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var anchorText = anchorText || "Click Here";
|
|
|
|
|
var location = location || "newTab";
|
|
|
|
|
var width = validateAndReturnDefaultIfFailed(width, "600");
|
|
|
|
|
var height = validateAndReturnDefaultIfFailed(height, "400");
|
|
|
|
|
|
|
|
|
|
return function (data, type, row) {
|
|
|
|
|
|
|
|
|
|
// restriction only for table display rendering
|
|
|
|
|
if (type !== 'display') {
|
|
|
|
|
if (type !== "display") {
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var url = data;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
url = new URL(data);
|
|
|
|
|
|
|
|
|
|
switch(location) {
|
|
|
|
|
case 'newTab' :
|
|
|
|
|
return '<a title="' + url + '" href="' + url + '" target="_blank">' + text + '</a>';
|
|
|
|
|
case 'popup':
|
|
|
|
|
return '<a title="' + url + '" href="' + url + '" target="popup" rel="noopener noreferrer" onclick="window.open(\'' + url + '\', \'' + text + '\', \'width='+width+',height='+height+'\'); return false;">' + text + '</a>';
|
|
|
|
|
switch (location) {
|
|
|
|
|
case "newTab":
|
|
|
|
|
return (
|
|
|
|
|
'<a title="' +
|
|
|
|
|
url +
|
|
|
|
|
'" href="' +
|
|
|
|
|
url +
|
|
|
|
|
'" target="_blank">' +
|
|
|
|
|
anchorText +
|
|
|
|
|
"</a>"
|
|
|
|
|
);
|
|
|
|
|
case "popup":
|
|
|
|
|
return (
|
|
|
|
|
'<a title="' +
|
|
|
|
|
url +
|
|
|
|
|
'" href="' +
|
|
|
|
|
url +
|
|
|
|
|
'" target="popup" rel="noopener noreferrer" onclick="window.open(\'' +
|
|
|
|
|
url +
|
|
|
|
|
"', '" +
|
|
|
|
|
anchorText +
|
|
|
|
|
"', 'width=" +
|
|
|
|
|
width +
|
|
|
|
|
",height=" +
|
|
|
|
|
height +
|
|
|
|
|
"'); return false;\">" +
|
|
|
|
|
anchorText +
|
|
|
|
|
"</a>"
|
|
|
|
|
);
|
|
|
|
|
default:
|
|
|
|
|
return '<a title="' + url + '" href="' + url + '" target="_blank">' + text + '</a>';
|
|
|
|
|
return (
|
|
|
|
|
'<a title="' +
|
|
|
|
|
url +
|
|
|
|
|
'" href="' +
|
|
|
|
|
url +
|
|
|
|
|
'" target="_blank">' +
|
|
|
|
|
anchorText +
|
|
|
|
|
"</a>"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch(e) {
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|