Skip to content
Discussion options

You must be logged in to vote

There are two approaches: to show pricestd in separate columns by m_pricelist_version_id, either reshape the rows before passing them to the DataTable or use a display function that looks up the value in the array.

1. Reshape rows before passing to DataTable

<script>
  const PRICELIST_IDS = [5, 13];

  const headers = [
    { key: 'name', value: 'Product' },
    ...PRICELIST_IDS.map((id) => ({
      key: `pricestd_${id}`,
      value: `Price (v${id})`,
    })),
  ];

  $: rows = rawData.map((row) => ({
    ...row,
    ...Object.fromEntries(
      PRICELIST_IDS.map((id) => [
        `pricestd_${id}`,
        row.m_productprice?.find((p) => p.m_pricelist_version_id === id)?.pricestd,
      ])

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by metonym
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants