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

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

问题描述

我正在查看 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.

假设您的数据数组像示例一样被称为数据",以下内容应该适合您:

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天全站免登陆