2

How to add hidden columns in the lightning data table? Thanks.

Is there anything I can add to typeAttributes/cellAttributes to make it invisible?

2
  • 2
    Your data that feeds your data table can have elements you choose not to display. Would that suit your objective? I'm not sure what a hidden column would get you.
    – David Reed
    Commented Mar 27, 2019 at 23:52
  • @DavidReed I'd have added that as an answer, honestly. There's no reason for hidden input fields when you can store whatever you want in each row.
    – sfdcfox
    Commented Mar 28, 2019 at 3:28

1 Answer 1

6

Expanding upon my comment.

The data storage that feeds your <lightning:dataTable> can contain, and often does contain, elements you choose not to display. Your Apex server controller could, for example, query many fields that you need at some point during the front-end lifecycle, but which don't get shown in this particular table.

You might even annotate your data store with extra attributes that don't get displayed at all or which are only used indirectly in the data table. One thing I often do is add a URL field to my data table items:

cases.forEach(function(item) {
    item['URL'] = '/lightning/r/Case/' + item['Id'] + '/view';
}

But that could just as easily be an internal status of some kind that your component uses to track its own state, and doesn't surface to the user.

To not display such a field, just don't list it in your <lightning:dataTable>'s columns attribute. It'll be ignored.

1
  • Thanks, David. I really appreciate your feedback. This is solved :) Commented Mar 28, 2019 at 16:16

You must log in to answer this question.

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