javascript - 在 extjs 可编辑网格数据中编辑值时如何删除脏标志?

标签 javascript json extjs extjs6

一个extjs可编辑网格数据网格有以下json数据命名为

data.json

{
  "rows" : [ {
    "record_id" : 101,
  }, {
    "record_id" : 102,
    "data" : "",
  }, {
    "record_id" : 103,
    "data" : 62,
  }, {
    "record_id" : "104",
    "data" : "62",
  } ]
}

在单元格中切换时,一些数据单元格显示有脏标记。实际上,从用户的 Angular 来看,没有任何数据被更改。这是一个演示。当然也有数据缺失,或者字符串,或者整型混合。这种情况发生在现实生活中,因为用户不关心编程类型等。问题是如何清理脏标志,因为实际上没有更改数据,并且在提交时,所有类型的数据都做没有出现在 getChanges() 中?如果发生任何数据更改,例如 62 到 625,它应该显示一个脏标志;如果反向,例如 625 到 62,它不应该显示脏标志,直到单击“保存”。

enter image description here

这是与测试相关的其他文件。

data.html

<!-- <!DOCTYPE html> -->
<html>
<head>
<meta name="google" content="notranslate" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=10, user-scalable=yes">
<title>Gride Data Testing</title>

<script type="text/javascript" src="https://examples.sencha.com/extjs/6.5.1/examples/classic/shared/include-ext.js"></script>
<script type="text/javascript" src="https://examples.sencha.com/extjs/6.5.1/ext-all-debug.js"></script>
<script type="text/javascript" src="https://examples.sencha.com/extjs/6.5.1/examples/classic/shared/options-toolbar.js"></script>

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/extjs/6.2.0/classic/theme-triton/resources/theme-triton-all.css">

<script type="text/javascript" src="data-ext-0.js"></script>

</head>
<body>

<div id="grid-example"></div>

</body>
</html>

data-ext.js

Ext.require([
  'Ext.grid.*',
  'Ext.data.*',
  'Ext.util.*',
  'Ext.state.*' ]);

Ext.onReady(function() {

  var myStore = Ext.create('Ext.data.JsonStore', {
    // http://docs.sencha.com/extjs/6.0.2/modern/Ext.grid.column.Column.html
    storeId : 'myStore_data',
    autoLoad : true,
    autoDestroy : true,
    proxy : {
      type : 'ajax',
      url : 'data.json',  // the file is defined as the above
      reader : {
        type : 'json',
        keepRawData : true,
        rootProperty : 'rows'
      }
    },
  });

  var grid = Ext.create('Ext.grid.Panel', {
    store : Ext.data.StoreManager.lookup('myStore_data'),
    columnLines : true,
    border : true,
    title : 'Grid Data Testing',
    columns : [ {
      text : "Record ID",
      dataIndex : "record_id",
      width : 200,
      format : '0',
      editor : {
        xtype : 'numberfield',
        allowBlank : true,
        allowNull : true,
      }
    }, {
      text : "Data",
      dataIndex : "data",
      width : 200,
      format : '0',
      editor : {
        xtype : 'numberfield',
        allowBlank : true,
        allowNull : true,
      }
    } ],
    selModel : {
      selType : 'cellmodel'
    },
    height : 230,
    width : 402,
    title : 'Grid Data Testing',
    renderTo : 'grid-example',
    viewConfig : {
      stripeRows : true
    },
    plugins : {
      cellediting : {
        clicksToEdit : 1
      }
    }
  });
});

最佳答案

您需要在编辑后提交您的数据,您可以在 celleditor 插件的 edit 事件 上执行此操作,如下所示:

我添加了一个控件,只有当起始值和新值相同时才提交,所以如果我更改单元格中的值,则不会提交记录

如果值为null,还需要检查originalValue和value是否不为null

如果您不需要提交,您可以使用此解决方法。 record.set 方法不是通过网格单元格编辑标记计算的。

   cellediting: {
                clicksToEdit: 1,
                listeners: {
                    edit: function (editor, context, e) {
                        if (context.originalValue === context.value ||
                        (!context.originalValue && !context.value)) {
                            context.record.set(context.field,context.value);
                            context.record.set(context.field,context.originalValue);
                        }
                    }
                }
            }

here you can see a working fiddle

代码已更新

关于javascript - 在 extjs 可编辑网格数据中编辑值时如何删除脏标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48284007/

相关文章:

javascript - 如何使用 Angular.js 在页面上显示从 JSON 检索的图像

extjs - ext js 选项卡面板 : which tab will be loaded by default?

javascript - 无法看到清晰的图片 Bootstrap LightBox

javascript - 跳过innerHTML中的空值

c# - 如何以标准方式返回数据?

c# - 在 Json.NET 中使用 FormatterAssemblyStyle.Simple 序列化 Type 类型的字段

javascript - 如何使用 css/Extjs 在悬停在另一个元素上时显示一个元素

Javascript如何解析JSON数组

javascript - react : Code Explanation for "PrevState" and "=>"

Javascript 不读取以 0 开头的数组项