Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:32:02+00:00 2026-05-31T06:32:02+00:00

I am trying create a search box which will search datatables. The search box

  • 0

I am trying create a search box which will search datatables.

The search box will be in the header for all pages for the site. When the user types in to the search box and then submits it will query the datatables.

I did find this:

<input type="text" id="myInputTextField">

oTable = $('#myTable').dataTable();
$('#myInpuTextField').keypress(function(){
      oTable.fnFilter( $(this).val() );
})

But I was unsure how to implement this as the search box will be in the header.

Any help advice would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:32:03+00:00Added an answer on May 31, 2026 at 6:32 am

    That code is correct. But everything depends on your setup. fnFilter takes only one required parameter which is the text to search. If you specify a second parameter you will filter only one column, otherwise it will search the textin all the table. You can of course filter more than one table at once

    //initialize table 1
    var oTable = $('#myTable').dataTable();
    //initialize table 2
    var oTable2 = $('#myTable2').dataTable();
    $('#myInpuTextField').keypress(function(){
          //filter table one
          oTable.fnFilter( $(this).val() );
          //filter table two
          oTable2.fnFilter( $(this).val() );
    })
    

    EDIT – for your last comment. To do that you must post the value to the server with a form.
    Then you “preload” the posted value in the input field and call fnFilter. Something like (in PHP)

    <?php
    $postedSearch = $_POST['posted'];
    ?>
    <script type="text/javascript">
    $(function(){
      var oTable = $('#idOfTable').dataTable();
      if($('#myInputTextField').val() !== ''){
         oTable.fnFilter($('#myInputTextField').val());
      }
    }())
    </script>
    <input type="text" id="myInputTextField" value="<?php echo $postedSearch ?>" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a link, which will, allow my paginated search to
I am trying to create a simplified search box that will match multiple columns
I am trying to create a search bar for website which searches the database
Hi I'm trying to create a search box to search customer by last name
I'm trying to build a search engine that will check a list and then
I'm trying to create a 'search box' that matches users by name. The difficulty
I am trying to create an app which displays search results for a query
I'm trying to create a good match query for an auto-complete search box using
I am trying to create a search box to look for invoices in database.
I am trying to create a search box to go with my UITableView, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.