数据表-如何在URL中传递搜索参数 [英] Datatables - how to pass search parameter in a url

查看:98
本文介绍了数据表-如何在URL中传递搜索参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够链接到带有数据表的页面,该数据表将在url中传递搜索参数值。目的是使具有数据表打开的页面已使用搜索值参数预先过滤。

I would like to be able to make a link to a page with a datatable which would pass a search parameter value in the url. The goal is to have the page with the datatable open pre-filtered with the search value parameter.

我设置了一个jsfiddle来处理一些示例数据。

http://jsfiddle.net/lbriquet/9CxYT/10/

I've set up a jsfiddle to work in with some sample data.
http://jsfiddle.net/lbriquet/9CxYT/10/

例如,向jsfiddle网址添加参数,以便显示页面时将搜索输入值设置为 firefox,并过滤表格以仅显示搜索匹配项。

The idea would be to add a parameter to the jsfiddle url so that the page would display with the search input value set to "firefox", for example, and the table filtered to show only the search matches.

任何帮助将不胜感激!

推荐答案

这是一个古老的问题,但是当出现问题时它仍然会弹出寻找解决方案。这是我所做的工作。

This is an old question, but it still pops up high when searching for a solution. Here's what I did to make it work.

$(document).ready( function() {
  
  // First, get the search parameter. Here I use example.com#search=yourkeyword
    var searchHash = location.hash.substr(1),
        searchString = searchHash.substr(searchHash.indexOf('search='))
		                  .split('&')[0]
		                  .split('=')[1];
  
  
  $('#example').dataTable( {
    "oSearch": { "sSearch": searchString }
  } );
} )

这篇关于数据表-如何在URL中传递搜索参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆