[ui-grid 3.0.0] Provide a flushDirtyRows(rowArray) API to selectively flush certain rows
Please see my plunkr: http://plnkr.co/edit/2A7jsaCZvBRu8iV615F1
Here you'll see a sample based on tutorial 205. The difference being that we send all changes in a batch after pressing "Save Rows" instead of saving automatically (rowEditWaitInterval = -1 mode as I call it).
I was just wondering, how could we handle server side errors of batch operations (ex: a PUT that handles modification of multiple rows at once)?
There's a success callback associated with the resource call, but there is also the resolution of promises for each individual row (in saveRow() callback).
Not seen: In my own Save Rows button, I am allowing modifications and additions of rows to be handled in the same method. I do a PUT for the adds, and a POST for the updates. I call flushDirtyRows at the very end to allow for adds/changed rows to be processed on the client-side (they are already committed, in the success case, on the server side
Currently, added and modified rows are both marked as dirty by ui-grid framework.
Questions:
-
Is there a better way that allows me to associate the success callback with the operation of flushing certain rows (the ones that were changed) versus others (the ones that were added)?
-
If not, I guess I'm asking if you can provide a flushDirtyRows(arrayOfRows) to selectively flush certain rows?
I didn't provide this method as I thought it would give a lot of grief with error handling - the error handling relies on a resolve or reject of a promise for an individual row, doing this in a batch I thought would give difficulty in working out which row failed to save. It also had ugly semantics - it means you'll call the server to save some rows, and it needs to save some rows and return errors on others, which didn't make much sense to me (usually a server call works for all data or fails for all data).
For those reasons I didn't build a batch function. The intent of rowEdit is that all the saves are asynchronous, in which case it shouldn't really matter that they're going as individual calls. I'm happy to accept a pull request to extend it so long as the API for it is clean and logical.
@PaulL1 OK thanks for your insight. I've been thinking about this some more. I need to figure out a way to "accept all or none" on the server-side (some sort of rollback transnationality), which in this case is a Spring REST service talking to a database. Of course, on the database, the updates probably boil down to individual rows, but I'm thinking there probably is a way to fail the whole batch. I'll look into that. I'll think about the PR for the flushDirtyRows(dirtyRows[]) API just for completeness sake, even though most people might not use it.