问题描述
我希望能够链接到带有数据表的页面,该数据表将在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来处理一些示例数据。
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中传递搜索参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!