Skip to main content
added 178 characters in body
Source Link
ssspfx
  • 299
  • 3
  • 16

How do I give unique id to dropdown control and people picker to be able to edit and perform operations only for that row in the array map? I have already given a kaykey for each div and I have unique id which is the unique item.id.

Below is the rendering : Edit is editing the entire dropdown rows instead of that selected one. enter image description here

How do I give unique id to dropdown control and people picker to be able to edit and perform operations only for that row in the array map? I have already given a kay for each div and I have unique id which is item.id.

How do I give unique id to dropdown control and people picker to be able to edit and perform operations only for that row in the array map? I have already given a key for each div which is the unique item.id.

Below is the rendering : Edit is editing the entire dropdown rows instead of that selected one. enter image description here

Source Link
ssspfx
  • 299
  • 3
  • 16

React List Keys row edit PNPJS dropdown & People Picker

I am trying to enable row edit for a particular array of People Picker and Dropdown controls. Below is what I have so far,

<table cellSpacing="1">
            <div className={styles.tableStyle} >  
            <tr>
              <td className={styles.CellStyle}>Division</td>
              <td className={styles.CellStyle}>Assignee</td>
              <td className={styles.CellStyle}>Added by</td>
            </tr>
          </div> 
            {this.state.ListItems.reverse().map(function(item,key){
              return(<div className={styles.rowStyle} key={item.Id}> 
                <tr>
                  <td><div><Stack tokens={stackTokens}><Dropdown required={true} 
                  onChange={this._getDropdownItem1} 
                  placeholder="Select a Division" 
                  options={this.state.DivisionListItems} 
                  selectedKey={item.Division} 
                  styles={dropdownStyles}  
                  disabled={this.state.isEdit}/>
                  </Stack></div></td>
                  <td>
                    <div><PeoplePicker context={this.props.context} 
                  personSelectionLimit={3} 
                  groupName={""}  
                  showtooltip={true} 
                  tooltipMessage="Select multiple users for assigning the item" 
                  isRequired={true} 
                  disabled={this.state.isEdit} 
                  ensureUser={true} 
                  selectedItems={item.Assignee.map(assigne=>assigne.Title)} 
                  showHiddenInUI={false} 
                  principalTypes={[PrincipalType.User]} 
                  defaultSelectedUsers={item.Assignee} 
                  resolveDelay={1000} /></div></td>
                  <td></td>
                  <td><div><label className='ms-Label'>{item.Author.Title}</label></div></td>
                </tr>
                 <div className={styles.editdiv}><DefaultButton className={styles.button} onClick={()=>{this.handleEdit(item,key)}} iconProps={{iconName:'Edit'}}></DefaultButton><DefaultButton className={styles.button} onClick={()=> { if (window.confirm('Are you sure you wish to delete this item?')){this.handleDelete(item.Id)}  this.onCancel(item) }} iconProps={{iconName:'Delete'}}></DefaultButton></div>
              </div>
                 );
            }.bind(this))}
          </table>

Handle edit function below

@autobind
public handleEdit(Division,Users){
  let selectedUsers = [];
   for (let item in Users) {
     selectedUsers.push(Users[item].Title);
   }
  this.setState({editusers:selectedUsers,Dropdownvalue:Division,isEdit:false });
  console.log("event is" + event);
}

How do I give unique id to dropdown control and people picker to be able to edit and perform operations only for that row in the array map? I have already given a kay for each div and I have unique id which is item.id.