0

We wanted to hide a few columns present in the datable on mobile. We are using lightning-datatable, as this is standard we can't use media queries on it to hide or show a particular column based on the device. Is there a way we can acheive this in LWC?

1 Answer 1

3

You can detect the user client's form factor, then decide what fields to display based on that:

import FORM_FACTOR from '@salesforce/client/formFactor';

...

const columns = {
  Large: [ { ... }, ... ],
  Medium: [ { ... }, ... ],
  Small: [ { ... }, ... ],
};

export default class MyComponentName extends LightningElement {
  columns = columns[FORM_FACTOR];
}      
1
  • It helped. Thank you so much! Commented Aug 8, 2022 at 18:17

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