views:

581

answers:

1

The question is likely confusing and I apologize. I wasn't sure how best to word it.

I am using jqGrid in a jQueryUI dialog which is inside a form. The user will use this form to create and edit Events.

Upon editing, the user can click a button to open a dialog showing a grid of saved locations for the event. I want to give them the ability to remove saved locations, but I don't want to delete them right away on the server because they may decide to not save the changes on the main form.

What I'd like to do is build an array containing the IDs of what locations they delete with the default delete navigator delete button. When I confirm deletion of rows, it wants an editurl, but I don't want to delete them right now.

Is there a good way to track their deleted records and then delete them once they save the event? I am wondering if I should create a server-side collection/file and read it once the Event itself is saved; I have no idea what the best approach is for this.

Thank you in advance :)

+1  A: 

Here are some high-level guidelines for how you can accomplish this:

Instead of using the navigator's delete button, you could create your own button - name it delete and give it a custom event hander. Then when a row is deleted, add its ID to an array of deleted rows, and update a hidden field in the form which contains all of the deleted rows. When the form is POST-ed back to the server, this field can then be used to do the actual deletes.

To save the ID's to the hidden field, you could use the stringify method from json2.js to write it as JSON. You would then need to decode the JSON array using ASP.NET MVC to extract the ID's.

Does this help at all?

Justin Ethier
Quite well, thanks Justin! This may need its own SO question, but when using hidden fields, can I set a field's value to all array values or should I do it one by one (one hidden field per array value). My concern is that I could be sending a LOT of data back to the server. I'll look into stringify, however - thanks again :)
Dan
You're welcome, glad to help :) I recommend using `stringify` to set the field's value to all array values. Alternatively you might be able to dynamically create hidden fields, and/or only have a certain number. But using `stringify` with a single one is a good balance of simplicity and flexibility.
Justin Ethier
The only reason I'd stick with not using `stringify` is because I have a custom model binder that already binds everything for me. Still, it'll be worth a look as I'm not a huge fan of creating a billion hidden fields :)
Dan