{hero}

columns.defaultContent

Since: DataTables 1.10

Set default, static, content for a column.

Description

Often you may wish to have static content in a column, for example simple edit and / or delete buttons, which have events assigned to them. This option is available for those use cases - creating static content for a column. If you wish to create dynamic content (i.e. based on other data in the row), the columns.render option should be used.

Additionally, this option can be useful when loading JSON data, as the value set here will be used if the cell value from the JSON is found to be null (for example, you might set a default string of Not available.

Type

This option can be given in the following type(s):

Examples

Show an information message for a field that can have a null or undefined value:

$('#example').dataTable( {
  "columns": [
    null,
    null,
    null,
    {
      "data": "first_name", // can be null or undefined
      "defaultContent": "<i>Not set</i>"
    }
  ]
} );

Show an empty string when a field's value is null or undefined value:

$('#example').dataTable( {
  "columns": [
    null,
    null,
    null,
    {
      "data": "office", // can be null or undefined
      "defaultContent": ""
    }
  ]
} );

Create an edit button in the last column with columnDefs:

$('#example').dataTable( {
  "columnDefs": [
    {
      "data": null,
      "defaultContent": "<button>Edit</button>",
      "targets": -1
    }
  ]
} );

Create an edit button in the last column with columns:

$('#example').dataTable( {
  "columns": [
    null,
    null,
    null,
    {
      "data": null,
      "defaultContent": "<button>Edit</button>"
    }
  ]
} );

Related

The following options are directly related and may also be useful in your application development.