is there a way to download database collection via a webpage aka an export button i can add to a page to download a csv file witch has filters
like this but for wix?
Hi,
With some clever coding this could be achieved by using https functions.
The url below returns a csv file and i created it using http functions, you can see the code for it below
https://idoi240.wixsite.com/uploadbtn/_functions/getList/list.csv
In this example I manually construct the CSV data as a simple string and return it when a get request is sent for the aforementioned url.
To adjust this code and prepare it for deployment you will have to create a function that queries the relevant collection (optionally by using query ), construct it according to CSV file rules and then return it in the response body. I leave this part to your capable hands
In addition, you can control the filename and extension the function returns with the ‘Content-disposition’ tag, which also tells the browser to download the file instead of displaying it inline.
import {ok, notFound, serverError} from 'wix-http-functions';
let csvData = `Start Date ,Start Time,End Date,End Time,Event Title ,All Day Event,No End Time,Event Description,Contact ,Contact Email,Contact Phone,Location,Category,Mandatory,Registration,Maximum,Last Date To Register
9/5/2011,3:00:00 PM,9/5/2011,,Social Studies Dept. Meeting,N,Y,Department meeting,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,High School,2,N,N,25,9/2/2011
9/5/2011,6:00:00 PM,9/5/2011,8:00:00 PM,Curriculum Meeting,N,N,Curriculum Meeting,Chris Gallagher,cgallagher@schoolwires.com,814-555-5179,High School,2,N,N,25,9/2/2011`
//create your own function to generate the csvData variable.
export function get_getList(request) {
let options = {
"headers": {
"Content-Disposition": `attachment; filename="list.csv"`
},
"body": csvData
};
return ok(options);
}
Feel free to share your solution here
Good luck!
thanks heaps
can i set it to take data for “#dataset1”
i dont know why im feeling lost
how to add it to a page
Hi Cameron,
http functions is considered backend code.
Using dataset in backend code is not possible, you will need to use wixData query to filter and get the results.
You can read more regarding http functions here
Once you get the http function to work as intended the final step is adding links to your site pages.
$w("#getListBtn").link = "https://idoi240.wixsite.com/uploadbtn/_functions/getList/list.csv";