在SlickGrid中保存更改 [英] Saving changes in SlickGrid

查看:136
本文介绍了在SlickGrid中保存更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,
我在看SlickGrid,我可以看到如何编辑单元格的示例,但是是否保存这些更改。我还没有找到一个例子,告诉我如何做到这一点。

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.

推荐答案

保存SlickGrid的窍门是实现该网格将更新您在编辑单元格时创建网格时提供的数据数组。

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

然后我保存的方式是在表单中包含一个提交按钮和网格下方的隐藏字段。我将提交事件进行陷阱并使用 JSON插件串行化该数组并将其放置在隐藏字段中。在服务器端,您将收到一个JSON字符串,您可以反序列化,循环并写入数据库。

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, loop through and write to the database.

假设您的数据数组被称为data样品,以下应该适合你:

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>

这篇关于在SlickGrid中保存更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆