Ext.Js 4数字字段默认值

时间:2011-08-24 09:30:51

标签: extjs numbers default

问题是:如何设置 xtype的默认值:'numberfield' 我在Ext.Js 4的文档中发现你应该设置字段。

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Number

value:Object。

使用。

初始化此字段的值

唯一的问题是,当我定义值:23 时,没有任何反应。 也许我正在对覆盖其行为的代码做一些事情。你可以找到的代码如下:

/// <reference path="ext-4.0/ext-all.js" />
Ext.define('IssueInventoryPartGrid.view.inventorypart.Issue', {
    extend: 'Ext.grid.Panel'
    , alias: 'widget.issueinventorypartlist'
    , store: 'IssueInventoryParts'
    , title: 'Issue Inventory Part'
    , selModel: 'cellmodel'
    , plugins: [
        Ext.create('Ext.grid.plugin.CellEditing', {
            clicksToEdit: 1
        })
    ]
    , width: 523
    , height: 600
    , loadMask: true

    , initComponent: function () {
        this.columns = [
            {
                header: 'Id'
                , dataIndex: 'Id'
                , hideable: false
                , hidden: true
                , flex: 1
            }
            , {
                header: 'Quantity to Issue'
                , dataIndex: 'QtyToIssue'
                , hideable: false
                , flex: 1
                , editor:
                {
                    xtype: 'numberfield'
                    , hideTrigger: true
                    , value: 99
                    , minValue: 0
                    , disabled: false
                    , allowBlank: true
                    , decimalPrecision: 4

                }
            }
            , {
                header: 'Available'
                , dataIndex: 'AvailableQty'
                , flex: 1
            }
            , {
                header: 'Batch Number'
                , dataIndex: 'BatchNumber'
                , flex: 1
            }
            , {
                header: 'Stock Address'
                , dataIndex: 'StockAddressName'
                , flex: 1
            }
            , {
                header: 'Quantity On Hand'
                , dataIndex: 'QtyOnHand'
                , flex: 1
            }
            , {
                header: 'Reserved Quantity'
                , dataIndex: 'ReservedQty'
                , flex: 1
            }
            , {
                header: 'Total Cost'
                , dataIndex: 'TotalCost'
                , flex: 1
            }
            , {
                header: 'Date Received'
                , dataIndex: 'DateReceived'
                , flex: 1
                , renderer: Ext.util.Format.dateRenderer('d/m/Y')
            }
        ];

        this.callParent(arguments);
    }
});

最好的问候,

Tito Morais

1 个答案:

答案 0 :(得分:1)

你正在做的事情没有错,但我所知道的是你正在使用来自商店的数据加载网格,这意味着网格将始终占用商店的价值和通过插件设置的价值不会出现在现场。

我建议,如果您打算为QtyToIssue数据索引设置默认值,那么您可以使用模型定义来设置默认值并确保来自商店的数据不存在不包含QtyToIssue字段。 该模型可能如下所示:     

Ext.define("IssueInventoryPartGrid.model.Issue", {
    extend: "Ext.data.Model",
    fields: [
        {
            name: "id", 
            type: "string"
        },
        {
            name: "QtyToIssue",
            type: "float",  // or "int" depending on your data
            defaultValue: 99  // default value to set
        }
    ]
});

通过这样做,模型将为每个不具有QtyToIssue字段的商店记录分配默认值。 尝试一下,或者你可以据此提出建议。 GBU