File: %24.fn.dataTable.util.escapeRegex%28%29.xml

package info (click to toggle)
datatables.js 1.10.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,348 kB
  • sloc: xml: 10,397; php: 4,448; sh: 521; makefile: 21
file content (52 lines) | stat: -rw-r--r-- 2,198 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?xml version="1.0" encoding="UTF-8" ?>
<dt-api group="static">
	<name>$.fn.dataTable.util.escapeRegex()</name>
	<summary>Escape special characters in a regular expression string</summary>
	<since>1.10.4</since>

	<type type="function">
		<signature>escapeRegex( str )</signature>
		<description>Escape special characters in a regular expression string.</description>
		<param type="string" name="fn" default="false">
			String to have regex special characters escaped
		</param>
		<returns type="string">Escaped string</returns>
	</type>

	<description>
		When working with regular expressions it can often be useful to escape input so formatted strings with characters that have special meaning in a regular expression will simply perform a character match. There are a number of special characters in Javascript's regular expressions and DataTables requires the ability to escape these strings internally (for user input of search data) - this method exposes that ability externally.

		This is a utility method that is provided for use by extension and plug-in authors. Its use does not directly effect a DataTable or DataTables configuration. It is used internally by DataTables and is made available in the public API to help promote code reuse for extension authors.
	</description>

	<example title="Perform an escape match search using `-tag select` elements"><![CDATA[

var table = $('#example').DataTable();

table.columns().indexes().flatten().each( function ( i ) {
	var column = table.column( i );
	var select = $('<select><option value=""></option></select>')
		.appendTo( $(column.footer()).empty() )
		.on( 'change', function () {
			// Escape the expression so we can perform a regex match
			var val = $.fn.dataTable.util.escapeRegex(
				$(this).val()
			);

			column
				.search( val ? '^'+val+'$' : '', true, false )
				.draw();
		} );

	column.data().unique().sort().each( function ( d, j ) {
		select.append( '<option value="'+d+'">'+d+'</option>' )
	} );
} );

]]></example>

	<related type="option">searching</related>
	<related type="option">columns.searchable</related>
	<related type="api">search()</related>
	<related type="api">column().search()</related>
</dt-api>