i am using key value dropdown in my table instead of value it is getting key while export. is there any function for customize data for export plugin and how to use.
// Define your Handsontable instance with dropdown settings
var hot = new Handsontable(document.getElementById(‘yourTable’), {
data: yourData, // Your data array
colHeaders: true,
columns: [
// Example column with dropdown settings
{ data: ‘yourColumnName’, type: ‘dropdown’, source: [
{ key: ‘Key1’, label: ‘Label1’ },
{ key: ‘Key2’, label: ‘Label2’ },
{ key: ‘Key3’, label: ‘Label3’ }
]}
// Add more columns as needed
],
});
// Export configuration
var exportPlugin = hot.getPlugin(‘exportFile’);
exportPlugin.downloadFile(‘csv’, {
exportHiddenColumns: true,
exportHiddenRows: true,
columnHeaders: true,
mimeType: ‘text/csv’,
charset: ‘utf-8’,
columnDelimiter: ‘,’,
rowDelimiter: ‘\r\n’,
filename: ‘exported_data.csv’,
customizeData: function (data) {
// Iterate through the data and replace dropdown keys with labels
return data.map(function (row, rowIndex) {
return row.map(function (cell, colIndex) {
var cellMeta = hot.getCellMeta(rowIndex, colIndex);
if (typeof cell === ‘object’ && cellMeta && cellMeta.chosenOptions) {
var dropdownData = cellMeta.chosenOptions.data;
var key = cell.key;
var matchingOption = dropdownData.find(function (option) {
return option.key === key;
});
return matchingOption ? matchingOption.label : cell;
}
return cell;
});
});
},
});