I get my primary key after I insert a new record for the newly created record. If I refresh the page, I get all data fine but I dont want to refresh the entire page. I tried to do $('#mygrid').igGrid("dataBind") but this just bind the grid data what we have already on the page. New record is still not loaded with new primarykey which is returned from database.
How do I bind the primary key with the grid and new record? Please help.
Hello Sarojanand,
sarojanand@gmail.com said:When I try to update the row, all data in the row is disappeared. if I click on cancel button, I see the data again but to update the row I have to add all fields. Can you see can be the issue?
You see this because your record from the data source cannot be found. This is caused by column type mismatch when igGridUpdating is looking for the record by its PK, thus you should define a data type for your column like this:
col.For(c => c.ProductID).HeaderText("ProductID").DataType("number");
sarojanand@gmail.com said:Also another problem, if I make my primary key field as ReadOnly so that nobody can edit it, I don't see the updated Key id anymore and old issue persist.
This problem should be resolved with my suggestion above i.e. I cannot reproduce it when I have DataType() defined. If you see it even if you define data type for your PK please attach a sample for me to investigate.
Hope this helps,Martin PavlovInfragistics, Inc.
I did implement your answer on http://es.infragistics.com/community/forums/p/84192/420302.aspx#420302 and now I can see the updated row with correct primary key. but a new strange problem came. When I try to update the row, all data in the row is disappeared. if I click on cancel button, I see the data again but to update the row I have to add all fields. Can you see can be the issue?
Also another problem, if I make my primary key field as ReadOnly so that nobody can edit it, I don't see the updated Key id anymore and old issue persist.
Hi Martin,
Yes I am using MVC helper wrapper for databinding. I have attached a txt file for you to have a look. All I want is when I add a new row, the product id (mvc action is returning it) should be binded with this so that I can instantly update the record without refreshing page / views. Update requires primary key.
Please have a look at the attached file and let me know where I am doing wrong and how to fix it.
From your description is not clear whether you're using the igGrid MVC helper wrapper for data binding as well as updating. If you use it calling igGrid.dataBind will make a remote request and refresh the primary key values, but you said this is not the case. In order for me to understand your scenario can you provide more information on:
Are you using igGrid MVC helper wrapper?
How do you bind igGrid to data? Is it remote data or local data? Do you make custom Ajax call to get the data?
How do you save updates made to igGrid (inserts, updates, deletes) to the database? Are you calling igGrid.saveChanges?
Do you have igGrid.updateUrl configured?
I've answered a similar question to yours, but the customer was using igGrid MVC helper wrapper. You can check the following forum post for an example of updating the PK value of newly created record on demand without the need for re-binding:
http://es.infragistics.com/community/forums/p/84192/420302.aspx#420302.
Hello,
Thank you for posting in our community.
A possible solution for updating the data source is setting the autoCommit option to true and handling the editRowEnded. When editing a row is performed the updated row values could be passed to the database. I have added bellow a code snippet demonstrating how the latest values of the updated row could be fetched (in bold bellow):
$("#grid1").igGrid({
primaryKey: "ProductID",
autoCommit: true,
columns: [
{ headerText: "Product ID", key: "ProductID", dataType: "number" },
{ headerText: "Product Name", key: "Name", dataType: "string" },
{ headerText: "Product Number", key: "ProductNumber", dataType: "string" },
],
width: '500px',
features:
[{
name:"Updating",
enableAddRow: true,
enableDeleteRow: true,
enableUpdateRow: true,
editRowEnded: function(evt, ui){ alert(ui.values.ProductID); }
}],
dataSource: products
});
I have also attached the whole sample for your reference.
If you have any further questions don’t hesitate to contact me again.