4

I have extended LightningDatatable:

export default class DispatchConsoleDataTable extends LightningDatatable {

   static customTypes = {

       smartCalendarCell: {
           template: calendarCell,
           standardCellLayout: false,
           typeAttributes: []
       }
   };
}

using this template:

<template>
    <c-dispatch-console-calendar-cell data-navigation="enable" cell-value={value}></c-dispatch-console-calendar-cell>
</template>

and this cell definition:

<template>
    <template for:each={cellArray} for:item="cell">
        <lightning-layout key={cell.Header} multiple-rows="true">
            <template if:true={cell.IsPM}>
                <lightning-layout-item size="6"></lightning-layout-item>
            </template>
            <lightning-layout-item size={cell.Size}>
                <lightning-formatted-text class={cell.Class} value={cell.Header}></lightning-formatted-text>
            </lightning-layout-item>
            <template if:true={cell.IsAM}>
                <lightning-layout-item size="6"></lightning-layout-item>
            </template>
            <template if:true={cell.HasFromTo}>
                <template if:true={cell.IsPM}>
                    <lightning-layout-item size="6"></lightning-layout-item>
                </template>
                <lightning-layout-item size={cell.Size}>
                    <lightning-formatted-text class={cell.Class} value={cell.FromTo}></lightning-formatted-text>
                </lightning-layout-item>
                <template if:true={cell.IsAM}>
                    <lightning-layout-item size="6"></lightning-layout-item>
                </template>
            </template>
        </lightning-layout>
    </template>
</template>

Everything is working fine except I would like to override the default vertical alignment of the cells, which seems to be center alignment:

enter image description here

Question: How do I change the vertical alignment for my custom cells to be "top"?

Thanks.

2
  • have you tried anything in particular? For instance, what if you add <lightning-layout vertical-align="start" to your cell definition? Jul 12, 2021 at 22:22
  • Yes I've tried all the usual suspects. No luck yet.
    – Dave C
    Jul 13, 2021 at 12:03

2 Answers 2

2
+50

Unfortunately you cannot do this with lightning-datatable but it's worth an Idea on IdeaExchange.

Here's why:

  • there's no attribute that exposes vertical alignment
  • Shadow DOM prevents you from modifying this with CSS in your custom cell. You wouldn't be able to bypass the two LWC wrappers (lightning-primitive-custom-cell-factory and lightning-primitive-custom-cell) and other elements that are in the way to get to the parent th element.

enter image description here

1
  • Well that's a shame. Thanks for the info, POZ.
    – Dave C
    Jul 16, 2021 at 20:55
-3

@Dave C Try using padding css style, please find below which i tried.

enter image description here

For the purpose of explaining, i pushed the cell value to top and did not align center. In order to achieve the above, i gave padding-bottom:50px to push my content to the top of the cell. Also not sure if you tried margin:auto; top:0.

enter image description here

Let me know if the above solution helps!

2
  • 2
    you cannot simply do that in the context of a namespaced component in LWC, as the title states "Lightning Datatable Subclass" the shadow boundary wont allow you to do this. This does not answer the question.
    – glls
    Jul 15, 2021 at 2:33
  • Thanks for trying to help Sunil, but glls is right.
    – Dave C
    Jul 15, 2021 at 12:28

You must log in to answer this question.

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