Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1175
Update Primary Key from Web API Response
posted

I've successfully used the igGrid to hook into our Web API.  Create, Remove and Delete operations are firing nicely and playing nicely together.  The only scenario that is currently failing is this:

  1. User creates a new record.
  2. igGrid creates a new ID - specifically -1.
  3. An API request is sent to create the new record with an ID of -1.
    POST:  /api/carrier
  4. API creates the new record and returns a request with the actual ID of 100.
  5. I need to update the primary key of record in the grid to 100.
  6. User deletes the new record.
    DELETE:  /api/carrier/-1        (WRONG)
    DELETE:  /api/carrier/100      (EXPECTED)

    Server won't be able to find -1.

In the "iggridupdatingrowadded" event I call "SaveChanges" to the grid to force the API call.

rowAdded: function (e, ui) {
    var original = ui;

    ui.owner.grid.saveChanges(function (record, status, response) {
        var row = this.findRecordByKey(original.rowID);

        row[original.owner.grid.options.primaryKey] = record[original.owner.grid.options.primaryKey];

        this.updateRow(original.rowID, row);
    });
}

When the transaction commits, it is failing to map the transaction with an -1 ID when it should be 100. 

Technical Details:

v14.2

Method: _commitTransaction

this.origDs has a record value of -1.

Unhandled exception at line 244, column 17855 in http://localhost:51580/admin/Scripts/IG/js/infragistics.core.js

0x800a138f - JavaScript runtime error: Unable to set property 'Id' of undefined or null reference

How can I correctly programmatically change the primary key value so the entire grid will function as normal?

Thanks,

Parents
No Data
Reply
  • 17590
    Verified Answer
    Offline posted

    Hello,

    Thank you for posting in our community.

    What I can suggest in order to have a matching ids on the client and server is to bind igGrid to the new(updated) data on every success callback of the saveChanges function. This could be achieved by updating the igGrid data source instance with the values from the underlying data base. The new data could be sent in the response and afterwards used to data bind igGrid. For example:

    //add the updated data with the new id`s matching actual records in the response and send it back to the success callback

    $(".selector").igGrid("saveChanges", function (data) {
        //Set
        $(".selector").igGrid("option", "dataSource", data);
        $(".selector").igGrid("dataBind");
    }

    I hope you find this suggestion helpful.

    Please let me know if you have any additional questions regarding this matter.

Children