Skip to content

Instantly share code, notes, and snippets.

@mubin986
Created May 26, 2025 11:06
Show Gist options
  • Save mubin986/4605952a42d690b6a6e5b5f72c78a4ee to your computer and use it in GitHub Desktop.
Save mubin986/4605952a42d690b6a6e5b5f72c78a4ee to your computer and use it in GitHub Desktop.
let headers = [];
document.querySelectorAll('.tabulator-col').forEach(header => {
let text = header.innerText.trim();
headers.push(text || ''); // Handle empty headers
});
let rows = [];
document.querySelectorAll('.tabulator-row').forEach(row => {
let rowData = [];
row.querySelectorAll('.tabulator-cell').forEach(cell => {
let text = cell.innerText.trim();
text = text.replace(/\u2013/g, "-").replace(/\u2019/g, "'");
rowData.push(text);
});
if (rowData.length) {
rows.push(rowData);
}
});
// Convert to CSV with headers and UTF-8 BOM
let csvContent = "\uFEFF"; // UTF-8 BOM
csvContent += [headers, ...rows].map(row =>
row.map(val => `"${val.replace(/"/g, '""')}"`).join(',')
).join('\n');
// Trigger download
let blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
let link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "export.csv";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment