0

I have a datatables table setup

Mainpage.php

new DataTable('.dataTable',{ "pageLength" : 100, scrollCollapse: true, scrollY: '500px', "bPaginate": false, columnDefs: [{ "defaultContent": "-", "targets": "_all" }] }); 

When a user does a thing, I reload the page. I would like the reloaded page to have the search filter activated after reload.

Here is the code on the page where a user does their thing.

 <script> $('body).on('//Some event),function(){ //get the search term var searchTerm = $('#dt-search-2').val(); //reload window.location.href = url+"?tab=licenses&search="+searchTerm; }); </script> 

On the MainPage.php

<script> //get the search term from the parameters in url var searchTerm = "<?php if (isset($_GET['search'])){ echo $_GET['search']; }?>"; //populate the search field in datatables $('#dt-search-2').val(searchTerm); //What can i use here to trigger the actual filter? </script> 

I have tried

 $('#dt-search-2').trigger('click'); $('#dt-search-2').focus(); 

Currently, I see the reloaded page and the value of the searchterm is populated in #dt-search-2, i just cant get the filter to actual go.

2
  • Look at the official documentation - so, use something like var table = $('#example').DataTable(); followed by table.search( 'foo' ).draw(); (see search()). If that is not sufficient, please provide a minimal reproducible example.CommentedMar 21 at 1:32
  • I expect there are already lots of questions and answers on Stack Overflow covering different variations of this.CommentedMar 21 at 1:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.