Reputation: 11
I use the Datatables script with YADCF filters. I need to create a new "Copy URL" button that copies the page URL with the applied filters. I added a script that uses the "URLSearchParams" and allows to get the filtered column data. For example, if I type example.com/table?category=DAA URL manually in the browser address bar, it filters the data in the "Category" column and shows the relevant result. However, I am not sure how to improve this script and:
I uploaded the whole code here: https://plnkr.co/edit/GuT04wDkcGDzV7y5?preview The part below allows to use the parameters in filters:
const urlParams = new URLSearchParams(window.location.search);
const whichCategory = urlParams.get('category');
if ( whichCategory !== null ) {
yadcf.exFilterColumn( productTableVar, [[0, whichCategory]]);
}
const whichFunction = urlParams.get('function');
if ( whichFunction !== null ) {
yadcf.exFilterColumn( productTableVar, [[1, whichFunction]]);
}
const whichBit = urlParams.get('bits');
if ( whichBit !== null ) {
yadcf.exFilterColumn( productTableVar, [[3, whichBit]]);
}
An important note: the columns include content in HTML format with special characters (& or /) and spaces.
I will appreciate your help. Thank you.
Upvotes: 1
Views: 123