extjs可编辑网格数据网格具有以下名为的json数据:

data.json

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


切换单元格时,某些数据单元格显示带有脏标志。实际上,从用户的角度来看,没有任何数据被更改。这是一个演示。当然,有数据丢失,字符串或整数类型混合。这种情况发生在现实生活中,因为用户不在乎编程类型等。问题是如何清除脏标志,因为实际上并没有更改的数据,并且在提交时,所有类型的数据都可以不会显示在getChanges()中?如果发生任何数据更改,例如62到625,它应该显示一个脏标志;如果倒退,例如从625到62,则在单击“保存”之前,它不应显示脏标志。

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

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

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 event上进行操作,如下所示:

我添加了仅在开始值和新值相同时才提交的控件,因此如果我在单元格中更改值,则记录不会提交

如果该值为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/

10-11 14:17
查看更多