0

I want to display array of objects in 2 columns. what is the easiest method to display the list as two columns?

const columns = [
    {
      subHeading: "A",
      subText: ["1", "2"]
    },
    {
      subHeading: "B",
      subText: ["3", "4"]
    },
    {
      subHeading: "C",
      subText: ["5", "6"]
    },
    {
      subHeading: "D",
      subText: ["7", "8"]
    }
  ];

Desired display on LWC Page:

A B
C D
1
  • What have you tried so far? What part of that isn't working? Please edit your question with more information about where you're stuck, or this question is likely to be closed.
    – Nick C
    Commented Sep 6, 2023 at 4:18

1 Answer 1

2

Although the question is a bit unclear , I'll try to provide a general approach.

We can achieve the desired result using a combination of lightning-layout & setting its container width as below :

<div class="container">
      <lightning-layout multiple-rows="true">
        <template for:each={columns} for:item="col">
          <lightning-layout-item key={col.subHeading} padding="horizontal-small">
            <p>{col.subHeading}</p>
          </lightning-layout-item>
        </template>
      </lightning-layout>
  </div>

CSS :

.container {
  width: 5vw;
}

You can try various combinations : https://developer.salesforce.com/docs/component-library/bundle/lightning-layout-item/example

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .