Extjs GridPanel验证

时间:2011-09-06 11:00:27

标签: javascript extjs extjs4

当IN1> OU1或IN2> OU2 ??

时,如何进行验证功能?

这是我的代码(带有roweditor插件的网格面板)

{
 xtype: 'gridpanel',
 height: 250,
 width: 400,
 title: 'My Grid Panel',
 columns: [
           {
             xtype: 'datecolumn',
             text: 'IN1',
             dataindex 'F02ORAIN1',
             field: {
               xtype: 'timefield',
               id 'editF02ORAIN1'
             }
           },
           {
             xtype: 'datecolumn',
             dataindex 'F02ORAOU1',
             text: 'OU1',
             field: {
               xtype: 'timefield',
               id 'editF02ORAOU1'
             }
           },
           {
              xtype: 'datecolumn',
              text: 'IN2',
              dataindex 'F02ORAIN2',
              field: {
                xtype: 'timefield',
                id 'editF02ORAIN2'
              }
           },
           {
             xtype: 'datecolumn',
             text: 'OU2',
             dataindex 'F02ORAOU2',
             field: {
               xtype: 'timefield',
               id 'editF02ORAOU2'
            }
          }
 ],
 plugins: [
    Ext.create('Ext.grid.plugin.RowEditing', {
    })
 ]
}

2 个答案:

答案 0 :(得分:4)

我认为最好的方法是使用字段validator配置:

// ...
{
    xtype: 'datecolumn',
    text: 'IN1',
    dataIndex: 'F02ORAIN1',
    field: {
        xtype: 'timefield',
        id: 'editF02ORAIN1',
        validator: function(value) {
            if (!Ext.getCmp('editF02ORAOU1').getValue()) return true;
            if (this.getValue() > Ext.getCmp('editF02ORAOU1').getValue())
              return 'IN1 should be less then OU1';
            return true;
        }
    }
}, {
    xtype: 'datecolumn',
    dataIndex: 'F02ORAOU1',
    text: 'OU1',
    field: {
        xtype: 'timefield',
        id: 'editF02ORAOU1'
    }
},
// ...

Here is demo

答案 1 :(得分:0)

不要使用getCmp(除非调试你不应该这样做),而是将数据与Store中的值进行比较。

相关问题