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,
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://ko.infragistics.com/community/forums/p/84192/420302.aspx#420302.
Hope this helps,Martin PavlovInfragistics, Inc.
I did implement your answer on http://ko.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.
The problem was in the rebindData JavaScript function in the Addresses.cshtml. The data.AddressKey variable is a string, thus when you set this value in the grid you got a data type mismatch and the result is empty editors. That's why you need to call parseInt on data.AddressKey in order to make it number.
Here is the modified version (in bold is the modification which I made):
//update new id to new rowfunction rebindGrid(data) { if (typeof data.AddressKey != 'undefined') { grid.igGridUpdating("setCellValue", recOldID, "AddressID", parseInt(data.AddressKey)); $("#ba_addresses > tbody > tr[data-id='" + recOldID + "']").attr("data-id", data.AddressKey); grid.data("igGrid").dataSource.commit(); grid.data("igGrid").dataSource.allTransactions().length = 0; }}
Best regards,Martin PavlovInfragistics, Inc.
Hi Martin,
Thank you very much, it worked.
Just a quick question - why I cant use grid.igGrid("dataBind") instead of creating separate method like rebindGrid(data) what I m doing? Am I calling it on wrong event?
Another issue, sometime when I edit a row,
List<Transaction<Address>> transactions = gridModel.LoadTransactions<Address>(HttpContext.Request.Form["ig_transactions"]);
transaction.Count shows 0. This doesn't happen everytime. Next time you submit and it works fine. Any idea why its causing this issue?
sarojanand@gmail.com said:Just a quick question - why I cant use grid.igGrid("dataBind") instead of creating separate method like rebindGrid(data) what I m doing? Am I calling it on wrong event?
Of course you can, but this requires different grid configuration which includes setting .DataSourceUrl() and adding a new controller action decorated with GridDataSourceAction attribute. Attached you can find the Addresses.cshtml and BusinessAssociateController.cs. These are the files which I modified in order to demonstrate this scenario. Note that by default all grid features in this case will be remote. However I do not recommend you to use re-binding (calling igGrid.dataBind method), because it has 2 drawbacks:
1. It reloads the current page, which is unnecessary network traffic.
2. It causes a flickering which will probably annoy the user.
sarojanand@gmail.com said: Another issue, sometime when I edit a row, List<Transaction<Address>> transactions = gridModel.LoadTransactions<Address>(HttpContext.Request.Form["ig_transactions"]); transaction.Count shows 0. This doesn't happen everytime. Next time you submit and it works fine. Any idea why its causing this issue?
I haven't seen such a behavior. I suspect that it can be a timing issue. You can try to use setInterval function to delay the igGrid.saveChanges method execution.
Here is an example:
I am following up to check if you have any further questions. If so, don’t hesitate to contact us again.
Hi Dimka,
I marked this as answer for grid related issues however I have posted another query for igHtmlEditor. I am trying it online on your website in IE 9 and some toolbar functions like redo/undo etc. doesn't work. Same thing is happening when I am using it locally.
Can you please see that?