Hi,
Currenly,i am facing following issue:
1) for insert,update,delete:
we are using WEBAPI in our project, if any error occurs while making Insert,Update,Delete, WebApi Returning that Error string. but currently if any error occures at webapi , Igrrid still insert,update,delete that respective record into the grid .
with help of Error string, how can i restrict iggrid to
a).add new row with that record,
b).update existing record,
c).delete record
2). i am using ('iggridupdatingeditrowended', function (evt, ui){} for update, but if i have click on cell for edit and click on cancel button without editing any field, still ('iggridupdatingeditrowended', function (evt, ui){} event get fired , it should get fire only when i would click on Done button.
Thanks,
Yogesh
Hello Yogesh,
I am attaching a small sample demonstrating some of the points that we talked about. It uses autoCommit: false, calls saveChanges every time the end-user changes something through Updating's UI and uses success and error callbacks. Generally speaking the success callback is not needed unless you want to do something specific, as the data source will detect that the saveChanges call is successful and commit the change for you. You do need to have an error callback to rollback unsuccessful ones though.
The sample is pure HTML + JS and I am simulating an endpoint with Mockjax. To show both successes and errors I am returning errors for all POST (create) requests and successes for all PUT and DELETE ones. So if you create a row you should expect it to get removed after the error is handled but all other changes should get persisted.
I hope this helps! Please, let me know if I can be of further assistance.
Best regards,
Stamen Stoychev
Hi Stamen ,
Thanks for Reply, i am trying to Implement ,what you suggest.
how can we update,insert and delete manually if the autoCommit is false? can you please attach sample for same.
Regards,
Hello,
As I already mentioned autoCommit: true doesn't work that well when you have server-side validation on user input. It basically tells the grid to consider every edit valid and save it in the local data source. Such edits cannot be rolled back programmatically for when the server rejects them. The best you can do is to immediately call dataBind after you receive an error from the WebAPI so that the grid can get refreshed and display only valid records.
If I am not understanding you correctly and you just want to block editing from ending when the PK is -1, you could also do it with adding a validator for that column. I am attaching a simple sample with a validator blocking the PK column from receiving a negative value. Please, have in mind this validation is only for end-user input during edit mode.
Hi Stamen,
Thanks for Reply.
On my code Autcommit is true , if the error occurs at webApi ,it return ERROR in string, but grid still showing me that record with Primary key ID=-1 because i have set defaultvalue -1 for primarykey, but when i reload the page that row is disappearing, that means its not get committed in Datasource.
how i can restrict iggrid for adding row with primary ID=-1.
Please check below attached Screenshot
yogesh
Regarding error handling with WebAPI, the answer may depend on how you have set your restSettings and at which point you call saveChanges but in general, you will want to disable auto-committing (autoCommit: false) then call saveChanges with both a success and an error callback. In the success callback you should call a manual commit so that the change gets persisted in the local data source. In the error callback you should rollback the faulty edit.
By design the editRowEnded event gets fired when editing for a row ends, regardless of the result. Should you want to detect if the end-user wanted to persist the change (by clicking the Done button or hitting Enter) or not (Cancel/Esc) you should use the event argument "update" as listed in the API reference.
I hope this helps! Thank you for using Infragistics forums!
Please, let me know if you have any other questions or concerns!