I have a function to warn the user if the grid didn't refresh due to unsaved changes:
{ name : 'Updating', dataDirty: function(evt, ui) { // warn the user show_warning("You have unsaved changes. The invoices will be refreshed after you Save or Revert your changes."); return true; },
For example, if the user edits a search criteria on the page that would normally refetch the rows. They instead get a warning. The dataDirty function returns true so that the grid ignores the new data being bound to it.
This works, but the console displays an uncaught exception:
Grid has pending transactions which may affect rendering of data. To prevent exception, application may enable "autoCommit" option of igGrid, or it should process "dataDirty" event of igGridUpdating and return false. While processing that event, application also may do "commit()" data in igGrid.
I do want to interrupt the grid from loading the new data, but without a messy message appearing in the console. Is there a way to catch or suppress this error? Or is there a better way to handle dirty data in general? Thanks.
Hi Matthew,
I believe that this exception tells clearly what should be done to prevent it. You have 3 options:
- enable 'autoCommit' option of the grid
- process 'dataDirty' event and return false
- process 'dataDirty' event and call ui.owner.grid.dataSource.commit()
If you have any further questions, please let me know.
Regards,
Tsanna
Tsanna,
If I am understanding correctly, none of those three options behaves as we wish. They all assume that we either want the commit to happen, or we want the user's changes to be quietly erased. We were looking for a hook that would allow us to cleanly interrupt the refresh.
I guess the right way to do this is to check for user changes before refreshing the dataSource, rather than catching the problem during the refresh with dataDirty. I see now that there is a pendingTransactions option that we can use for that.
So I think we have a path forward. Thanks for clearing up our misunderstanding about dataDirty.
Matt
(edit: fixed link)