{#if selection.length > 0}
{pluralize(selection?.length ?? 1, 'item') + ' selected'}
{/if}
{
return convertJsonToCsv(
selection.length > 0
? sortObjects(activeSorting, structuredObjects, true)
.filter(({ _id }) => selection.includes(_id))
.map((obj) =>
colSelection.length == 0
? obj.rowData
: Object.fromEntries(
Object.entries(obj.rowData).filter(([key, _]) =>
colSelection.includes(key)
)
)
)
: colSelection.length == 0
? sortObjects(activeSorting, objects, false)
: sortObjects(activeSorting, objects, false).map((obj) =>
Object.fromEntries(
Object.entries(obj).filter(([key, _]) => colSelection.includes(key))
)
)
)
}}
customText={selection.length > 0 || colSelection.length > 0
? 'Download selected as CSV'
: undefined}
/>
{
const actions = [
{
displayName: 'Download JSON',
icon: Download,
action: () => {
const json = JSON.stringify(objects, null, 2)
const blob = new Blob([json], { type: 'text/json;charset=utf-8;' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.setAttribute('href', url)
link.setAttribute('download', 'data.json')
link.style.visibility = 'hidden'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
}
]
if (selection.length > 0) {
actions.push({
displayName: 'Clear selection',
icon: Columns,
action: () => {
colSelection = []
selection = []
renderCount++
}
})
}
return actions
}}
>