最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trigger Datatables search after reload - Stack Overflow

programmeradmin2浏览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.

发布评论

评论列表(0)

  1. 暂无评论