{hero}

searchDelay

Since: DataTables 1.10.3

Set a delay for search operations.

Description

This parameter sets a delay between user input to the global search field (top right of every DataTable by default) and when the actual search operation is performed. This can be of particular use when using server-side processing and you don't want every keystroke to trigger an Ajax request for data.

This property's default value depends upon the serverSide option of DataTables:

  • 0 when in client-side processing mode,
  • 400mS when server-side processing.

Setting a value in the initialisation object will override with your value regardless of which mode is used.

Being able to control the call frequency has a number of uses:

  • Older browsers and slower computers can have their processing load reduced by reducing the search frequency
  • Fewer table redraws while searching can be less distracting for the user
  • Reduce the load on the server when using server-side processing by making fewer calls
  • Conversely, you can speed up the search when using server-side processing by reducing the default of 400mS to instant (0).

The value given for this property is in milliseconds (mS).

Prior to DataTables 2, this method used DataTable.util.throttle() and thus would trigger a search even if the user was still typing, just at a reduced call rate. As of DataTables 2 DataTable.util.debounce() is used to wait until the user has finished typing (more specifically until the given timeout has completed) before running the search.

Please note that this option effects only the built in global search box that DataTables provides. It does not effect the search() or column().search() methods at all. If you wish to be able to delay calls to those API methods use the utility method DataTable.util.debounce().

Type

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

Default

  • Value: null

When given as null DataTables will automatically assign a value that is suitable for the processing mode that the DataTable is operating in:

  • Instant - client-side processing
  • 400mS - server-side processing

Example

Set a 350mS delay for searching:

new DataTable('#myTable', {
	searchDelay: 350
});

Related

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