From 05414e143738de3c7fd09fc515f5b4528482629e Mon Sep 17 00:00:00 2001
From: Allan Jardine
Date: Thu, 21 May 2020 09:52:15 +0000
Subject: [PATCH] Update - example: Use initComplete for column filter example
---
.datatables-commit-sync | 2 +-
examples/api/multi_filter.html | 58 +++++++++++++++++++---------------
2 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/.datatables-commit-sync b/.datatables-commit-sync
index 6ddb239e..c8d70b17 100644
--- a/.datatables-commit-sync
+++ b/.datatables-commit-sync
@@ -1 +1 @@
-7a4382d11a7db5cae5e4b9311564c741b70c7dfd
+6bda0abd0cade0b2795f938b2a1d1686c3176024
diff --git a/examples/api/multi_filter.html b/examples/api/multi_filter.html
index 9ad41180..760bccbc 100644
--- a/examples/api/multi_filter.html
+++ b/examples/api/multi_filter.html
@@ -32,20 +32,23 @@ $(document).ready(function() {
} );
// DataTable
- var table = $('#example').DataTable();
+ var table = $('#example').DataTable({
+ initComplete: function () {
+ // Apply the search
+ this.api().columns().every( function () {
+ var that = this;
- // Apply the search
- table.columns().every( function () {
- var that = this;
+ $( 'input', this.footer() ).on( 'keyup change clear', function () {
+ if ( that.search() !== this.value ) {
+ that
+ .search( this.value )
+ .draw();
+ }
+ } );
+ } );
+ }
+ });
- $( 'input', this.footer() ).on( 'keyup change clear', function () {
- if ( that.search() !== this.value ) {
- that
- .search( this.value )
- .draw();
- }
- } );
- } );
} );
@@ -66,7 +69,9 @@ $(document).ready(function() {
This examples shows text elements being used with the column().search()
method to add input controls in the footer of the table for each column. Note that the
*index*:visible
option is used for the column selector to ensure that the column()
method takes into account any hidden columns when selecting the column to act upon.
+ "DataTables API method">column() method takes into account any hidden columns when selecting the column to act upon. initComplete
is used to allow for any
+ asynchronous actions, such as Ajax loading of data or language information.
@@ -566,20 +571,23 @@ $(document).ready(function() {
} );
// DataTable
- var table = $('#example').DataTable();
+ var table = $('#example').DataTable({
+ initComplete: function () {
+ // Apply the search
+ this.api().columns().every( function () {
+ var that = this;
- // Apply the search
- table.columns().every( function () {
- var that = this;
+ $( 'input', this.footer() ).on( 'keyup change clear', function () {
+ if ( that.search() !== this.value ) {
+ that
+ .search( this.value )
+ .draw();
+ }
+ } );
+ } );
+ }
+ });
- $( 'input', this.footer() ).on( 'keyup change clear', function () {
- if ( that.search() !== this.value ) {
- that
- .search( this.value )
- .draw();
- }
- } );
- } );
} );
In addition to the above code, the following Javascript library files are loaded for use in this example: