Nuxt Auto CRUD provides built-in support for exporting table data to Excel and PDF.
.xlsx file using the xlsx library.jspdf and jspdf-autotable.In any Auto CRUD table, click the Export button to see the available formats:
You can control which columns are included in your exports using the crud configuration in app/app.config.ts. This gives you the flexibility to hide sensitive fields like passwords or internal IDs from your exported documents.
// app.config.ts
export default defineAppConfig({
crud: {
exports: {
pdf: {
// Excluded from ALL resources in PDF
globalExclude: ['avatar', 'resetToken'],
// Resource specific overrides
resourceExclude: {
users: ['password', 'googleId'],
},
},
excel: {
resourceExclude: {
users: ['password'],
},
},
},
},
})
The export logic is encapsulated in the useExport composable. You can find it at app/composables/useExport.ts.
You can adjust the PDF appearance by modifying the exportToPDF function:
// app/composables/useExport.ts
autoTable(doc, {
headStyles: {
fillColor: [51, 65, 85], // Slate 700
// ...
},
// ...
})
To keep the server bundle lean and avoid compatibility issues on platforms like Cloudflare Workers, export libraries are loaded dynamically on the client side only.
const { jsPDF } = await import('jspdf')
const { default: autoTable } = await import('jspdf-autotable')