Hello Guys, In this post, I am going to show you an example that illustrate, how you can show boolean field as checkbox in lightning datatable.
Boolean field as checkbox in lightning datatable
If you use boolean column in datatable it show true/false text in column but their is small trick that can be used to display boolean field as checkbox without any design modification of datatable.
Trick - while building column attribute, type attribute must be set boolean in small letter for checkbox field.
Boolean in normal:
{label: 'Field label', fieldName: 'field api name',type: 'Boolean'}
Boolean in small:
{label: 'Field label', fieldName: 'field api name',type: 'boolean'}
You can see difference in above images, in first image where checkbox field type set with capital (Boolean) first letter, column value shows true/false text values. But in second image you can see tick mark in place of true value (for false it shows blank) because type attribute set with small (boolean) first letter.
Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.
2 Comments
This is not a trick. It's just there is no type 'Boolean' so it considers it as text by default.
ReplyDeleteHahaha, thank you for letting me know..!
DeletePost a Comment