/ Published in: jQuery
Uses the dataTables filter/search to provide a link to the term being filtered and copies a link to clipboard via ZeroClipboard. Requires the getURLParam, ZeroClipboard and dataTables jQuery plugins.
http://www.mathias-bank.de/jQuery/jquery.getParams.js
http://www.datatables.net/
http://code.google.com/p/zeroclipboard/
http://www.mathias-bank.de/jQuery/jquery.getParams.js
http://www.datatables.net/
http://code.google.com/p/zeroclipboard/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript" src="path/to/jquery.dataTables.min.js" ></script> <script type="text/javascript" src="path/to/jquery.getURLParam.js" ></script> <script type="text/javascript" src="path/to/ZeroClipboard/ZeroClipboard.js"></script> <script> jQuery(function() { jQuery(".dataTables_filter :input").after("<button id='clipLink'>Link to search</button>"); // set button for copy var oSearch = $.getURLParam("search"); //utilize the getURLParam plugin to return the ?search= param(s) e = jQuery.Event("keyup"); //set enter event e.which = 13 //enter key if (oSearch != null) { //must be null and not blank for a url jQuery(".dataTables_filter :input").val(oSearch.replace(/%20/g, ' ')).trigger(e)// find all url encoded spaces and replace them, fabricate enter press } jQuery("button#clipLink").zclip({ path: "path/to/ZeroClipboard/ZeroClipboard.swf", copy: function(){ if(jQuery(".dataTables_filter :input").val() == "") { alert("please enter a search term"); return false; } else { var pathname = window.location.href; searchTerm = jQuery(".dataTables_filter :input").val(); result = pathname.substring(5, pathname.indexOf('/')) + "path/to/datatables/page/?search=" + searchTerm; jQuery("#copiedLink").val(result); return jQuery("#copiedLink").val(); } } }); }); </script>