You need to sign in to do that
Don't have an account?
Shyamala Varadharajan
Dynamic picklist in LWC Datatable
I have a use case like in first column I need to dispaly some valuein first column which is a text value , according to that i need to make next column as dynamic which is picklist field and according to the second column the third column need to be dynamic which is picklist field. For Example,
Is this possible to do in lwc datatable. If yes can anyone help me how to acheive this. Thanks in advance.
Column A (Text) | Column B (Picklist) | Column c (Picklist) |
A | B C D (If user select D) | B C |
B | A C D (If user select A) | C D |
C | A B D(If user select B) | A D |
D | A B C(If user select C) | A B |
Is this possible to do in lwc datatable. If yes can anyone help me how to acheive this. Thanks in advance.
Hope you are doing good.
Achieving this using lightning data table will include some complexities, The simplest way to achive this is by using the HTML table.
It looks something like this.
I am attching the code for your reference, Let me know If this solution fullfills your requirement. Also please mark this answer as BEST to help the other community members. Thank you.
HTML
JS
All Answers
Check below reference example to get picklist values dynamically in lwc and that can help you.
https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/#:~:text=To%20fetch%20the%20picklist%20values,we%20need%20to%20call%20fields.
Please mark as Best Answer if above information was helpful.
Thanks,
Hope you are doing good.
Achieving this using lightning data table will include some complexities, The simplest way to achive this is by using the HTML table.
It looks something like this.
I am attching the code for your reference, Let me know If this solution fullfills your requirement. Also please mark this answer as BEST to help the other community members. Thank you.
HTML
JS
Thank you so much for your response this helps me a lot. I need one more clarfication. In my table the first column is a outputText field (I retrieve this value through API and not storing in SFDC)which will show the list like I added above, so according to that field i need to display the picklist field.Is that possible?
Yes that is definitely possible. Could you please give me more understanding about the outputText field which you are displying in the first column.
Are you trying to display all the values one by one in first column? In this example A,B,C,D in 4 seperate rows of the first column and in consecutive columns you want to display the picklists by leaving the selected options.
Yes Im making an API call where it returns A,B,C and D as a list . So I'm trying to create a table where it will have 4 columns. In Column A I'm trying to display each value one by one as a row.
C
D (If user select D)
C
C
D (If user select A)
D
B
D(If user select B)
D
B
C(If user select C)
B
Thanks you in advance
My Screen need to be like this,