Title: Calling DataTable search function on a Tablepress Table
Last modified: August 30, 2016

---

# Calling DataTable search function on a Tablepress Table

 *  Resolved [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/)
 * I have a tablepress table on a wordpress page.
 * I would like to call the search DataTable function on a Tablepress table. Like
   this:
 * var table = $(‘#example’).DataTable();
 * // #myInput is a <input type=”text”> element
    $(‘#myInput’).on( ‘keyup’, function(){
   table.search( this.value ).draw(); } );
 * How can I do this for a Tablepress table. Since my Tablepress table is on the
   page via shortcode, the instance has already been created.
 * How can I get an instance of the Tablepress table and call the search DataTables
   function?
 * I want to do a global filter search and redraw.
 * Thanks.
 * Don
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 13 replies - 1 through 13 (of 13 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760219)
 * Hi Don,
 * thanks for your question, and sorry for the trouble.
 * The best and most flexible way for that would then actually be to not let TablePress
   initialize DataTables. You could for example copy the initialization JS that 
   TablePress prints to the page but then turn off the “Use DataTables” checkbox.
   Then, you’d again add the initialization string to the page manually, with your
   desired changes/modifications.
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760250)
 * Actually, now that I think about it, what I really need is a way to change the
   table data on the fly. This is turning out to be really important for us.
 * 1. Where is the table data stored?
 * 2. We need to do a global search and replace on the table data at runtime.
 * 3. Then save the data back.
 * How can I do each of these steps?
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760252)
 * Hi,
 * the table data is stored as a JSON-encoded two-dimensional array in a Custom 
   Post Type “tablepress_table” in the wp_posts database table.
 * I don’t think that manipulating it there is a good idea. You might instead want
   to take a look at the filter hooks that are available when rendering the data,
   e.g. `tablepress_table_render_data` in the class-render.php file.
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760254)
 * More specifically, I need to get a local copy of the table data, search and replace
   and then display table. No need to save the data back since it is just a local
   copy.
 * How can I do that?
 * Important Note:
    I will pay for a customization to get this done.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760257)
 * Hi,
 * what do you mean with “local copy” here? Where is “local”? Why can’t you use 
   the Shortcode?
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760261)
 * Here is what I need by local:
 * 1. Find out where the data is being loaded.
    I call this the local data.
 * 2. Manipulate data before display
    Based on your response, it sounds like the
   following would be the best way: “You might instead want to take a look at the
   filter hooks that are available when rendering the data, e.g. tablepress_table_render_data
   in the class-render.php file.”
 * 3. Display table
 * **Can you please provide a real example of how I might perform a search and replace
   on the table table using item 2 with the class-render.php?
 * I would more than happy to pay for this example, because I need a good starting
   point for this issue and I am not sure I completely understand.
 * Thanks.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760262)
 * Hi,
 * yes, for this, the `tablepress_table_render_data` hook should be the best.
    You
   could use it with PHP code like
 *     ```
       add_filter( 'tablepress_table_render_data', 'donhhpress_hook_example', 10, 3 );
       function donhhpress_hook_example( $table, $orig_table, $render_options ) {
         /*
          * At this point, $table['data'] is a two-dimensional array of the
          * table data that you can manipulate as desired, e.g. in a loop.
          * The table ID (to check if you are in the correct table) is in $table['id']
          */
   
         return $table; // Leave this line in so that the filter returns the full table.
       }
       ```
   
 * that you paste into a small new custom plugin, or into your theme’s “functions.
   php”.
 * And thanks for wanting to donate, I really appreciate it!
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760275)
 * Awesome. Now I just need one more thing …
 * At the top of the page, the user will be select a dropdown value that is used
   to search and replace the data in the table.
 * The table shortcode is after this dropdown.
 * Once the user selects this, I need a way to reload the table on the same page
   as follows:
 * 1. User selects value in dropdown, which in turn sets a php $GLOBAL value;
 * 2. Force reload of tablepress table once the GLOBAL value is set by the user 
   so that the GLOBAL value can be used to manipulate the data in the table before
   it is display.
 * Does this make sense? And thanks.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760291)
 * Hi,
 * for that, you’d then simply need to create a form (with HTML code) that submits
   to the current page. The value of the dropdown should then be availabe in the`
   $_POST` array in PHP, which you can access in the filter hook PHP code.
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760294)
 * Yes, but how can I reload the tablepress data without reloading the page?
 * Is there a javascript call?
 * The dropdown that selects the search term is done via ajax, so no page reload
   takes place. And, with that said, would like to reload tablepress data without
   page refresh.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760301)
 * Hi,
 * no, sorry, there’s no direct JavaScript API here.
    The best solution that I can
   think of would be to use e.g. jQuery to load the entire page, but only show the
   table from it. The code of the TablePress Extension from [https://tablepress.org/extensions/table-ajax-refresh/](https://tablepress.org/extensions/table-ajax-refresh/)
   might be a good starting point for that.
 * Regards,
    Tobias
 *  Thread Starter [donhhpress](https://wordpress.org/support/users/donhhpress/)
 * (@donhhpress)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760308)
 * Thanks so much. Payment on the way.
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760313)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](http://wordpress.org/support/view/plugin-reviews/tablepress)
   here in the plugin directory. Thanks!

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Calling DataTable search function on a Tablepress Table’ is closed to
new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

 * 13 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/calling-datatable-search-function-on-a-tablepress-table/#post-6760313)
 * Status: resolved