1

I have a datatable where it's possible for the user to be able to inform the amount of products he/she wants to purchase. The problem is that as I'm making some columns editable (editable=true), the datatable automatically receives the row numbering column.

By making a column editable, the show-row-number-column attribute is always true and the number column is displayed.

I'm trying to force via CSS that the first column is hidden from the user, but it still doesn't work. Has anyone ever needed to make such a modification to hide the line numbering column? Please, could someone give me a north to do the best way?

.hide-numeric-col table th:first-child,
.hide-numeric-col table td:first-child {
   display: none !important;
   content: counter(none) !important;
   width: 0 !important;
}

.slds-table tr th:first-child {
   display: none !important;
   content: counter(none) !important;
   width: 0 !important;
}

<div class="slds-box hide-numeric-col">
  <lightning-datatable
    key-field="id"
    class="hide-numeric-col"
    data={lstProducts} hide-checkbox-column
    suppress-bottom-bar
    columns={returnColumns}
    draft-values={lstProductsDraft}
    oncellchange={handleCellChange}>
  </lightning-datatable>
</div>

enter image description here

1 Answer 1

1

You can't do this in any way that is supported. CSS is scoped to a component, so your component cannot affect the styles inside another component, and the table is hard-coded to show the row numbers when columns are editable. If you want a table that doesn't behave this way, you'll have to write your own.

3
  • sfdcfox, thanks for the reply. I thought it wasn't even possible, but even so I wanted to see if with the CSS I could have this possibility. Thanks again.
    – dsd
    Apr 25 at 14:59
  • @dsd There were some hacks that were possible, but the official position is that it can't be done. This is an intentional security/design feature of web components.
    – sfdcfox
    Apr 25 at 15:01
  • sfdcfox, I understand perfectly, and we have to follow the rules of the game. In the end, if I didn't use standard, I would have to customize it and that takes time, something the customer doesn't want.
    – dsd
    Apr 25 at 15:24

You must log in to answer this question.

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