0

So in my project I display user information in a table. I have a dropdown list and a button to filter the data. I am also able to edit a row of table data and I alert the user whenever they are already editing a user to prevent them from editing more than one user at a time. I get a problem when I first launch the web app what happens is the following:

  • I enter and submit user data
  • I start editing one user
  • Then I click on another user
  • The alert pops up telling me to finish editing the first user
  • I cancel editing
  • I try to filter the data
  • Nothing happens
  • I try to clear the filter
  • Nothing happens

It looks like the problem might have to do with how I have the alerts set up. I want to display the first and last name of the user that is being edited. So what I do is I have a global variable that represents the index of the user being edited and I assign it in the method where I start editing.

This is how I find the index of the user that is being edited

const editIndex = this.displayUsers.findIndex(item => item.id === this.displayForm.users[this.editUserIndex].id);

displayUsers is my filtered array and displayForm.users is the original data. editUserIndex is the index of the user that is being edited. I try to use that line of code to match the two ids of the two arrays.

And this is where I assign editUserIndex its value

 public startEdit(id: string): void{
      let startStr = "";
      //find the index of the user whose editing has started 
      for (let index in this.editCache){
        if(this.editCache[index].edit){
          startStr = index;
        }
      }
      
      let numStartIndex = parseInt(startStr);
      
      
      //set an index equal to current user being edited to be able to use in clearFilter()
      this.editUserIndex = numStartIndex;

What am I doing wrong?

4

0 回答 0