Tito
Tito

Reputation: 802

Ext.Js 4 numberfield default value

The problem is: How can I set a default value of a xtype:'numberfield' ? I found out at the documentation of Ext.Js 4 that you should set the value field.

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

value : Object.

A value to initialize this field with.

The only problem is, when I define the value:23 for example, nothing happens. Maybe I am doing something on the code that is overriding its behaviour. The code you can find bellow:

/// <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);
    }
});

best regards,

Tito Morais

Upvotes: 1

Views: 12563

Answers (1)

Shamsudeen Zziwa
Shamsudeen Zziwa

Reputation: 153

there is nothing wrong with what you are doing but what i know is that you are loading the grid with data from the store, this means that the grid will always take up the value from the store and the value set via the plugin won't surface in the field.

what i would suggest, if what you intend to do is set a default value for the QtyToIssue dataindex, then you could use the model definition to set a default value and make sure that the data from the store doesn't contain the QtyToIssue field. The model could look like this:

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
        }
    ]
});

by doing this, the model will assign a default value for each store record that won't be having a QtyToIssue field. try it out or you may advise accordingly. GBU

Upvotes: 1

Related Questions