Adding parameters to a URL to "pre-filter"
Adding parameters to a URL to "pre-filter"
nickelmedia
Posts: 12Questions: 0Answers: 0
Sorry I am going to use the wrong lingo I'm sure, but what I'm trying to do is create links that have parameters in the URL that will take me to my table and have the search field already filled in with the parameter.
example: http://mysite.com/list/?search=ABC
I'd want that link to take me to my table that lives at http://mysite.com/list/ and have the search box already filled in with "ABC" in it. I got as far as finding this code, which worked, but it's a hardcoded search and I want it to be a variable controlled via the URL.
[code]
$(document).ready( function() {
$('#example').dataTable( {
"oSearch": {"sSearch": "Initial search"}
} );
} )
[/code]
Here is my live example of my current code: http://live.datatables.net/etigif/3/edit
Any help would be greatly appreciated!
example: http://mysite.com/list/?search=ABC
I'd want that link to take me to my table that lives at http://mysite.com/list/ and have the search box already filled in with "ABC" in it. I got as far as finding this code, which worked, but it's a hardcoded search and I want it to be a variable controlled via the URL.
[code]
$(document).ready( function() {
$('#example').dataTable( {
"oSearch": {"sSearch": "Initial search"}
} );
} )
[/code]
Here is my live example of my current code: http://live.datatables.net/etigif/3/edit
Any help would be greatly appreciated!
This discussion has been closed.
Replies
Allan
Solved using the following script:
[code]$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
if (!results)
{
return 0;
}
return results[1] || 0;
}[/code]
changed oSearch to:
[code]"oSearch": {"sSearch": $.urlParam('search')}[/code]
I can now search with http://www.mysite.com/list/?search=ABC
I've updated my live example here: http://live.datatables.net/etigif/4/edit
Allan