{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).

When used with a renderer (columns.render) the default content is resolved after the rendering function. If the renderer returns null or undefined the value set for the default content will be used.

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:

new DataTable('#myTable', {
	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:

new DataTable('#myTable', {
	columns: [
		null,
		null,
		null,
		{
			data: 'office', // can be null or undefined
			defaultContent: ''
		}
	]
});

Create an edit button in the last column with columnDefs:

new DataTable('#myTable', {
	columnDefs: [
		{
			data: null,
			defaultContent: '<button>Edit</button>',
			targets: -1
		}
	]
});

Create an edit button in the last column with columns:

new DataTable('#myTable', {
	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.