I am trying to set up an igGrid to do CRUD via REST. I have two questions, either one of which might be enough to get us unstuck.
1. We bind the query results (JSON array) to the grid, as follows:
$.ajax({ type : 'GET', url : BASE_URL + '/ar_invoices', data : params, dataType : 'json', success : function(invoiceRows) { $("#ar_invoices").igGrid("option", "dataSource", invoiceRows); }, });
This works well for display. However, when I add the "Updating" feature and restSettings to the grid, things don't work. Not only does the grid not send any updates to the server, but the grid behavior is wrong:
So the first question is: can restSettings be used if the dataSource is NOT a URL, but is instead a JSON array? Every REST example I've seen uses a URL dataSource so I'm thinking that might be part of our problem.
2. To try and answer question #1 I tried to set our dataSource to the URL instead:
var url = BASE_URL + '/ar_invoices'; $("#ar_invoices").igGrid("option", "dataSource", url);
The GET request sent by the grid includes Accept = "*/*" in the header. Unfortunately the service supports both JSON and XML using the same URL. It relies on the Accept header to determine what format to send back, but defaults to XML. So we'd need the grid to explicitly request JSON in the header(*). Is there a way to customize the headers it sends?
(*) Note that the XML feed isn't working: igGrid is throwing a parse error. But as igGrid seems to prefer JSON (and so do we) we don't want to spend any time on the XML issue if we can help it.
FWIW we'd prefer the approach in #1, as this gives us full control of the Ajax query. (We might need that to work around CORS issues, for example.) So if there's nothing inherently wrong with that approach then I'll probably have to post a followup message with more details.
Thanks for any assistance,
Matt
Stamen,
Here is a self-contained example that generates the error. If I edit either of the editable columns, the first time I click Revert I get the error:
"Error: Grid has pending transactions which may affect rendering of data. To prevent exception [..]".
After that, the Revert button works. Your comments would be appreciated.
Thanks!
Hello Matthew,
The issues you have continue to be a mystery then. For example, the column templates can be used with hidden columns as evident from the small sample I am attaching.
If you are still experiencing any of those, I would suggest updating to the latest SR for 15.1. If this doesn't help I could create a private case for you where you would be able to attach your project (or some isolated part of it) which will help me find out what's wrong.
Best regards,
Stamen Stoychev
Sorry! I called it a row template but its actually a column template. I assume those are not retired, as it is working fine.
(The files all say version 15.1.20151.1005.)
Since you mentioned a row template, could you please let me know which version of the product you are using. We retired the rowTemplate option in 14.1 and using an older version could explain some of the issues you are having.
ss> either the specific configuration or some code of yours is trying to change the data view of the grid
ss> while there still are transactions (edits) not yet committed to the local data source. While the exception
ss> suggests two ways to avoid this completely, it will still be worthwhile to find the exact culprit.
I'm confused by this. The steps are: initialize grid, add a data source to it, the user edits a cell, the error happens. There is only one place in the code where the dataSource is replaced, and it is not getting called after the edit. There is no code that directly alters the data. If time permits I'll try to isolate the problem.
me> Add New Row is still not working properly on my live page
Fixed. This one was caused by my row template referencing a column "status" that is marked hidden. Apparently that's not allowed. Chrome reports:Uncaught Error: An error has occurred while trying to retrieve data source property: ${status}
.. And I see the same error in Firefox now. I wish it had displayed that error yesterday, but whatever.