views:

456

answers:

2

HI, I'm looking at SlickGrid and I can see example on how to edit the cell, however do I save these changes. I have yet to find an example that tells me how to do this.

A: 

The trick to saving the SlickGrid is to realise that the grid will update the array od fata that you supplied when creating the grid as the cells are edited.

The way I then save that is to include a form with a submit button and a hidden field below the grid. I trap the submit event and use the JSON plugin to serialise the array and place it in the hidden field. On the server side you'll receive a JSON string which you can deserialise loopp through and write to the database.

Assuming your array of data is called "data" like the samples, the following should work for you:

<form action="?" method="POST">
  <input type="submit" value="Save">
  <input type="hidden" name="data" value="">
</form>
<script>
  $(function() {
    $("form").submit(
      function() {
        $("input[name='data']").val($.JSON.encode(data));
      }
    );
  });
</script>
Jim OHalloran
HI Jim, that's the idea I have gone with. Thought there maybe some other implementations but guess not.That's fine, thanks.
Rubans
+1  A: 

While I'm personally using the JSON serialize and submit in a hidden field approach from my previous answer another approach could be to trap the onCellChange event fired by SlickGrid after a cell value has changed and make an Ajax call to the server to save the changed value. This will result in lots of small Ajax requests to the server (which may increase load) but updates the server as soon as changes are made.

Jim OHalloran
I have implement an example that way but I would prefer your first example where batch updates are processed but I can see the benefits of both, definetly great to see there's at least someone else outhere using it ;)
Rubans
I prefer the batch method myself, but I thought I'd add the other idea for completeness :)
Jim OHalloran