Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

During row add, the dummy PK cannot be changed to a user-specified one #12091

Closed
ChronosSF opened this issue Sep 16, 2022 · 8 comments
Closed
Assignees
Labels

Comments

@ChronosSF
Copy link
Member

ChronosSF commented Sep 16, 2022

Description

The most obvious way to support changing the dummy PK is by handling the rowEditStart event (if you don't want for the end-user to see the dummy negative numbers). However, changing the rowData from the event args like this throws an error.

  • igniteui-angular version: 12.3.x +
  • browser: n/a

Steps to reproduce

  1. Open the sample
  2. Start adding a row
  3. Observe the console

Expected result

The sample should either work or there should be a different mechanism to achieve this such as the generatePK event in jQuery.

Attachments

stoxrz--run.zip

@MayaKirova
Copy link
Contributor

@ChronosSF

I don't think we should allow changing the PK on rowEditStart or any other editing event.
Changing the PK while editing is generally not advisable (could break functionalities that depend on ids like the transactions etc.) so it doesn't make sense to allow it via event args while editing either.

You can change the PK for the adding record in the rowAdd event, which triggers just before the row is added.
In most real world scenarios the primary key column is not visible, nor editable, since it does not carry any meaningful information for the end-user. So you wouldn't need to change it before it actually is about to be added to the data in most cases.

Let me know if using the rowAdd event is enough for this use case. If not we could discuss further exposing some other event specifically for adding that exposes PK and/or the whole new row data object before starting edit on it.

@mddragnev
Copy link
Member

@ChronosSF, I agree with @MayaKirova and I have tested this with angular project and Entity Framework using SQLite.
In angular you should have rowAdd event handler

public rowAdd(event: IGridEditEventArgs) {
    console.log(event);
    this.cityService.addCity(event.newValue).subscribe(res => {
      if (res) {
        event.newValue.cityID = res.cityID;
      }
    }, err=> console.log(err));
  }

This will make a request to the controller so that the row can be added to the database and return the newly created object with correct ID (Note that firstly the id is a negative number).
In the controller we can do something like this:

 [HttpPost("add")]
        public ActionResult AddCity([FromBody]City City)
        {
           
            var tmp = new City
            {
                CityName = City.CityName,
                Description = City.Description,
                HolidayDate = City.HolidayDate,
                TrainStation = City.TrainStation,
                Population = City.Population
            };
            var addedCity = db.City.Add(tmp);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return BadRequest(e.Message);
            }
                      
             
            return Ok(addedCity.Entity);
        }

This way just before the row is added we change the rowID with the correct one which comes from the database.

@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Nov 21, 2022
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Nov 21, 2022
@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Jan 21, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Jan 23, 2023
@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Mar 25, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Mar 29, 2023
@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label May 29, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2023
@dkamburov dkamburov reopened this Jun 6, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Jun 6, 2023
@github-actions
Copy link

github-actions bot commented Aug 6, 2023

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Aug 6, 2023
@dkamburov dkamburov removed the status: inactive Used to stale issues and pull requests label Aug 9, 2023
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

There has been no recent activity and this issue has been marked inactive.

@github-actions github-actions bot added the status: inactive Used to stale issues and pull requests label Oct 9, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants