hyperLink

Displays url data in hyperLink with custom plcaeholder

  • Author: Lokesh Babu
  • Requires: DataTables 1.10+

This data rendering helper method can be useful when a hyperLink with custom 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. '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) The custom width of popup to display. Value is utilised on when 'location' is given as 'popup'.
  4. 'height' - type integer - (optional - default 400) The custom heigth of popup to display. Value is utilised on when 'location' is given as 'popup'.

Use

This plug-in can be obtained and used in multiple different ways.

Browser

This plug-in is available on the DataTables CDN:

JS

The plug-in will then automatically register itself against a global DataTables instance. This file can also be used if you are using an AMD loader such as Require.js.

Note that if you are using multiple plug-ins, it can be beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.

NPM

The plug-ins are all available on NPM (which can also be used with Yarn or any other Javascript package manager) as part of the datatables.net-plugins package. To use this plug-in, first install the plug-ins package:

npm install datatables.net-plugins

ES modules

Then, if you are using ES modules, import datatables.net, any other DataTables extensions you need, and the plug-in:

import DataTable from 'datatables.net';
import 'datatables.net-plugins/dataRender/hyperLink.mjs';

CommonJS

If you are using a CommonJS loader for Node (e.g. with older versions of Webpack, or non-module Node code) use the following method to require the plug-in:

var $ = require('jquery');
var DataTable = require('datatables.net');
require('datatables.net-plugins/dataRender/hyperLink.js');

Examples

// Display the hyperlink with 'Click Here', which open hyperlink in new Tab or new Window based on Browser setting
  $('#example').DataTable( {
    columnDefs: [ {
      targets: 1,
      render: DataTable.render.hyperLink()
    } ]
  } );
// Display the hyperlink with 'Download', which open hyperlink in new Tab or new Window based on Browser setting
  $('#example').DataTable( {
    columnDefs: [ {
      targets: 2,
      render: DataTable.render.hyperLink( 'Download' )
    } ]
  } );
// Display the hyperlink with 'Download', which open hyperlink in popup
  //        with size 600as width and 400 as height
  $('#example').DataTable( {
    columnDefs: [ {
      targets: 2,
      render: DataTable.render.hyperLink( 'Download', 'popup' )
    } ]
  } );
// Display the hyperlink with 'Download', which open hyperlink in popup
  //        with size 1000 width and 500 as height
  $('#example').DataTable( {
    columnDefs: [ {
      targets: 2,
      render: DataTable.render.hyperLink( 'Download', 'popup' , 1000, 500)
    } ]
  } );

Version control

If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!