Background: I am going to use this plugin https://www.npmjs.com/package/react-export-table-to-excel to export the table into an excel file. However, I am not able to use the ref method because there is a pagination and my requirement is to export all data. So I am using the second approach on the plugin documentation. I have data and columns (antd column). when I pass my data to the plugin and headers from column the exported excel doesnt show correct header for data fields.
I need to construct column data which returns me data but sorted in a way that props in the data object match the order of column. For example, DAN is the first entry in the column but in data, it's not the first prop. I need to make it the first prop so that my data props match the order of columns. Can someone write the function for me, please?
const data = [{
    "ltoId": null,
    "updatedOn": "2022-02-15T11:08:29Z",
    "updatedBy": "Randy",
    "comments": null,
    "dan": "657904/865",
    "lotNo": null,
    "volumeNo": "6",
    "folioNo": "5",
    "bookNo": "5",
    "pageNo": "7",
    "optedInPt": null,
    "optedInDate": "2022-03-04T19:06:54Z",
    "status": "FINALIZED"
  },
  {
    "ltoId": "S94182/137",
    "updatedOn": "2021-10-21T20:42:46Z",
    "updatedBy": "Gene",
    "comments": false,
    "dan": "608161/966",
    "lotNo": "0",
    "volumeNo": "6",
    "folioNo": "4",
    "bookNo": "8",
    "pageNo": "1",
    "optedInPt": false,
    "optedInDate": "2021-12-25T20:11:58Z",
    "status": "PENDING"
  }
]
const columns = [{
    title: 'DAN',
    dataIndex: 'dan',
  },
  {
    title: 'LTO ID',
    dataIndex: 'ltoId',
  },
  {
    title: 'Proposed Lot No',
    dataIndex: 'lotNo',
  },
  {
    title: 'Volume No',
    dataIndex: 'volumeNo',
  },
  {
    title: 'Folio No',
    dataIndex: 'folioNo',
  },
  {
    title: 'Book No',
    dataIndex: 'bookNo',
  },
  {
    title: 'Page No',
    dataIndex: 'pageNo',
  },
  {
    title: 'Opted in PT',
    dataIndex: 'optedInPt',
  },
  {
    title: 'Opt-in date',
    dataIndex: 'optedInDate',
  },
  {
    title: 'Transaction status',
    dataIndex: 'status',
  },
  {
    title: 'Updated on',
    dataIndex: 'updatedOn',
  },
  {
    title: 'Updated by',
    dataIndex: 'updatedBy',
  },
  {
    title: 'Comments',
    dataIndex: '',
  }
];
const columnData = [];
console.log(data, columns, columnData);