【问题标题】:Avoid the grid cell to get dirty unless the values is changed除非更改值,否则避免网格单元变脏
【发布时间】:2017-08-17 04:27:18
【问题描述】:

除非值改变,否则如何避免网格单元成为脏单元, 当我刚刚触摸时间单元时,它变成了一个脏单元,我如何避免它变脏, 这是Fiddle

这是我的网格

Ext.application({
    name: 'Fiddle',

launch: function () {

var myStore = Ext.create('Ext.data.Store', {
    storeId: 'simpsonsStore',
    fields: ['busname', 'time', 'typebus',],
    data: [{
        busname: 'ABCD',
        time: '15:30:00',
        typebus: 'AC Volvo',

    }, {
        busname: 'aaa',
        time: '13:30:00',
        typebus: 'Seater',

    }, {
        busname: 'AAAA',
        time: '18:30:00',
        typebus: 'Sleeper',

    }, {
        busname: 'ABCD',
        time: '19:30:00',
        typebus: 'AC Volvo',

    },]
});

var typebusStore = Ext.create('Ext.data.Store', {
    storeId: 'typeBusStore',
    fields: ['id', 'name'],
    data: [{
        id: 1,
        name: 'AC Volvo'
    }, {
        id: 2,
        name: 'Seater'
    }, {
        id: 3,
        name: 'Sleeper'
    }]
})

Ext.create('Ext.grid.Panel', {
    xtype: 'gridpanel',
    itemId: 'busTimegrid',
    pageSize: 1,
    title: 'BUS DEATILS',
    mapperId: 'getBusTime',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [{
        header: 'Bus Name',
        dataIndex: 'busname',
        editor: 'textfield'
    }, {
        text: 'Bus Time',
        dataIndex: 'time',
        xtype: 'gridcolumn',
        renderer: function (value) {
            if (value instanceof Date)
                return Ext.util.Format.date(value, 'H:i:s');
            else
                return value;
        },
        flex: 1,
        editor: {
            xtype: 'timefield',
            format: 'H:i:s',
            allowBlank: true,
            maskRe: /[0-9,:]/,
            listeners: {
                beforeselect: function (timefield, record) {
                    var grid = timefield.up('grid');
                    if (grid.store.find('time', record.data.disp) != -1) {
                        Ext.Msg.alert("Bus time already exist.");
                        return false;
                    }
                }
            }
        }
    }, {
        header: 'Bus TYpe',
        dataIndex: 'typebus',
        editable: true,
        renderer: function (value) {
                if (value !== null && value.length == 1) {
                    var store = this.getEditor().getStore();
                    return store.findRecord('id', value).get('name');
                }
                return value;
            },
        editor: {
            xtype: 'combo',
            displayField: 'name',
            valueField: 'id',
            editable: true,
        }
    }],
    selModel: 'cellmodel',
    plugins: {
        ptype: 'cellediting',
        clicksToEdit: 1,
    },
    height: 200,
    width: 400,
    dockedItems: [{
            xtype: 'toolbar',
            docked: 'bottom',
            items: [{
                xtype: 'button',
                flex: 1,
                text: 'Download to Excel',
                handler: function(b, e) {
                    b.up('grid').downloadExcelXml();
                }
            }]
        }

        ],
    renderTo: Ext.getBody()

});

}

});

【问题讨论】:

  • 将模型中的时间字段指定为日期类型。该值不同,因为它在编辑器中将字符串转换为日期。
  • 道歉埃文,但 Dint 让你.. 你能更具体。 @EvanTrimboli
  • @EvanTrimboli 更新了小提琴,现在我猜你应该能够看到我的问题,当你点击 Bus Time Column 并从中出来时,会出现红色的脏标志,所以我没有除非我更改值,否则希望它发生???
  • 模型中的typebus字段应该是type: 'date'

标签: extjs grid dirty-data


【解决方案1】:

试试这个方法 - Fiddle

Ext.application({
  name: 'Fiddle',
  launch: function() {
    run();
    window.show();
  }
});

function run() {
  var myStore = Ext.create('Ext.data.Store', {
    storeId: 'simpsonsStore',
    fields: [{
      name: 'busname',
      type: 'string'
    }, {
      name: 'time',
      type: 'date'
    }, {
      name: 'typebus',
      type: 'string'
    }],
    pageSize: 2,
    proxy: {
      type: 'memory',
      enablePaging: true
    },
    data: [{
      busname: 'ABCD',
      time: '2016-03-03 15:30:00',
      typebus: 'AC Volvo',

    }, {
      busname: 'aaa',
      time: '2016-03-03 13:30:00',
      typebus: 'Seater',

    }, {
      busname: 'AAAA',
      time: '2016-03-03 18:30:00',
      typebus: 'Sleeper',

    }, {
      busname: 'ABCD',
      time: '2016-03-03 19:30:00',
      typebus: 'AC Volvo',

    }, ]
  });

  var typebusStore = Ext.create('Ext.data.Store', {
    storeId: 'typeBusStore',
    fields: ['id', 'name'],
    data: [{
      id: 1,
      name: 'AC Volvo'
    }, {
      id: 2,
      name: 'Seater'
    }, {
      id: 3,
      name: 'Sleeper'
    }]
  })

  Ext.create('Ext.grid.Panel', {
    xtype: 'gridpanel',
    itemId: 'busTimegrid',
    pageSize: 1,
    title: 'BUS DEATILS',
    mapperId: 'getBusTime',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [{
      header: 'Bus Name',
      dataIndex: 'busname',
      editor: 'textfield'
    }, {
      xtype: 'datecolumn',
      text: 'Bus Time',
      dataIndex: 'time',
      format: 'H:i:s',
      flex: 1,
      renderer: function(value) {
        return Ext.util.Format.date(value, 'H:i:s');
      },
      editor: {
        xtype: 'timefield',
        format: 'H:i:s',
        allowBlank: true,
        maskRe: /[0-9,:]/
      }
    }, {
      header: 'Bus TYpe',
      dataIndex: 'typebus',
      editable: true,
      renderer: function(value, md, record) {
        var retValue = Array();
        if (Ext.isArray(value)) {
          Ext.each(value, function(id) {
            var ename = Ext.data.StoreManager.lookup('typeBusStore').findRecord('id', id).get('name');
            retValue.push(ename);
            console.log(retValue);
          });
        }
        if (retValue.length > 0) {
          return retValue.join(", ");
        }
        return value;
      },
      editor: {
        xtype: 'combo',
        displayField: 'name',
        valueField: 'id',
        editable: true,
        forceSelection: true,
        multiSelect: true,
        displayTpl: '<tpl for=".">' +
          '{name}' +
          '<tpl if="xindex < xcount">, </tpl>' +
          '</tpl>',
        store: typebusStore
      }
    }],
    selModel: 'cellmodel',
    plugins: {
      ptype: 'cellediting',
      clicksToEdit: 1,
    },
    height: 200,
    width: 400,
    dockedItems: [{
      xtype: 'pagingtoolbar',
      store: myStore, // same store GridPanel is using
      dock: 'bottom',
      displayInfo: true
    }],
    renderTo: Ext.getBody()
  });
}

【讨论】:

  • 嗨,Gilsha,我正在使用数据库中的映射器 ID 远程创建商店,我如何在那里声明该字段?我直接取mapper ID,根据数据库表创建store??
  • 好的。那么你是说你得到一个字符串数组作为字段配置?如果是,您可以使用 map 函数将其转换为客户端的对象数组并在存储中更新 store.model.setFields(newFieldsArray);
  • 嗨,Gilsha 在这个小提琴fiddle.sencha.com/#view/editor&fiddle/1sr2 中,最后一列即使我没有更改值,只需单击它就会使其成为脏单元格,如何避免它,??
  • 这里的问题是,你已经将列编辑器的valueField设置为ID。将其设置为 name,使其与记录中的 dept 属性值匹配。
  • 当我改变时,我禁止我改变值。
猜你喜欢
  • 2013-11-05
  • 2011-11-06
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
  • 2013-09-29
  • 1970-01-01
  • 2021-07-28
  • 2021-04-05
相关资源
最近更新 更多