6

Since I face many questions with this new base lightning component: lightning:datatable, I think it is better to have all the questions here in one place:

  1. I want to have a clickable row for "Click to edit" or "Click to Delete" functionality for each row, or a column for editing each row - how can I achieve that? The available checkboxes are not a good option because they can be multiple selected, and also I need many functionalities for each row (edit, delete, etc.).

enter image description here

  1. I tried to play with the data of the column and set attributes of text type column with the lightning:formattedText and of url type column with the lightning:formattedUrl - according to the doc you can set their attributes with setting in the column object typeAttributes: { attributeName: 'value' } - I could not set any attribute in this way (currency code does work - as in their example, but not all other attributes. Maybe a good example would help me.

  2. I created another Question for a problem with a displaying data from a parent field.

  3. I am trying to set the column width with my keyboard and with my mouse (according to the doc), but it is not working - why?

  4. I am trying to set a fixed initial size for some columns, and it is not working - here is my column array:

    [{label: 'Id', fieldName: 'Id', type: 'id', sortable: true, initialWidth: "50x"},
    
    {label: 'First Name', fieldName: 'FirstName', type: 'text', sortable: true},
    
    {label: 'Last Name', fieldName: 'LastName', type: 'text', sortable: true}]
    
  • 1. We can hide checkbox section using hideCheckboxColumn as true, but that would stop firing of getSelectedName event, thus it would be impossible to know which row was clicked. We cannot add events on columns thus we cannot have edit/delete buttons as table cell. 4-5. Are not working, I tested with the sample code they provide, i guess the table isnt suitable for real life implementations – Pranay Jaiswal Sep 24 '17 at 13:58
  • 4,5: Although you are setting this in the controller, I think there is an issue up that is probably being affected in the same way. It's an open issue at salesforce: success.salesforce.com/issues_view?id=a1p3A0000018C5BQAU – Chance Mar 28 '18 at 16:32
3

1) lightning:datatable does not allow to react to a click or double click over a particular row. This version of the component is read-only.

Row level action I think is what you need. Its coming in next release. Basically you can have a column type="actions" and the cells of that column have a buttonMenu with the actions you want to apply to rows.

is there a work around for that today? Not ideal but you can use checkboxes and actions button(edit, remove, view) outside of the table, those button could be disabled if more than one row is selected or no row is selected.

  • Thanks @ReinierGuerra, are you part of the dev team for this component? I think you have answered all of my questions except number 2 - I am trying to use the formattedText attributes but I fail, is there a reason for that? are all attributes supported? – Itai Shmida Sep 26 '17 at 9:23
  • 1
    It would be much better if you combine all your answers into one here. – Adrian Larson Sep 26 '17 at 17:28
  • Thanks. I see that the actions are not available on the datatable. How about if I create a table using standard js and html document.createelement("td").... How would I be able to add an action to it. I was able to add a class attribute but not an event listener. How would that be accomplished until the datatable supports it. – user8310 Nov 29 '17 at 8:20
3

5) I noticed you are using initialWidth: "50px", the value of that prop should be an javascript number e.g. initialWidth: 50

Also there is not type id. Hence that column is gonna fallback to type text which is OK in your case I think.

1

2) Which formattedText attributes you are trying to use? Not all the attributes for formatted* components are supported in lightning:datatable. In the case of formattedText, none so far.

can you provide the list of attributes are not working to you based on types and the use cases.

Thanks!

  • lightning:formattedUrl - cannot update onclick or any other attribute. besides, if I could update the body[] attribute - I could have done many things to this datatable, and that would make it very usefull. also - I tried to update attributes froom lightning:formattedText and couldn't – Itai Shmida Sep 27 '17 at 5:53
  • can't the documentation specify what can and what can't be done? because it says that all attributes could be handled with the typeAttributes param? – Itai Shmida Sep 27 '17 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.