Adding an empty row to a grid

前端 未结 2 2010
遇见更好的自我
遇见更好的自我 2021-01-16 03:52

I am trying to add rows to my grid.

I saw an example in the docs:

onAddRouteClick: function(){
// Create a model instance
var rec = new KitchenSink.m         


        
相关标签:
2条回答
  • 2021-01-16 03:59

    1.Create your model

     Ext.define('Product', {
            extend: 'Ext.data.Model',
            fields:
                [
                    { name: 'ProductID' },
                    { name: 'ProductName' },
                    { name: 'UnitPrice' },
                    { name: 'UnitsInStock' }
                ]
        });
    

    2.create your rowEditing

     var rEditor = Ext.create('Ext.grid.plugin.RowEditing', {
                clicksToEdit: 2,
                listeners:
                    {
                        edit: function (editor, e) { });
                    }
            });
    

    3.get Store and create your grid

     var grid = Ext.create('Ext.grid.Panel', {
                store: store,
                plugins: [rEditor],
                title: 'Products',
                columns:
                    [
                    ],
                dockedItems:
                [
                    {
                        xtype: 'toolbar',
                        dock: 'top',
                        items:
                            [
                                {
                                    xtype: 'button',
                                    text: 'Yeni',
                                    listeners:
                                        {
                                            click:
                                                {
                                                    fn: function () {
    
                                              store.insert(0, new Product());
                                                rEditor.startEdit(0, 0);
                                            }
                                        }
                                }
                        }
                    ]
            }
        ],
        width: 450,
        renderTo: Ext.getElementById('hede')
    });
    
    0 讨论(0)
  • 2021-01-16 04:18

    So you are trying to add a record to store right? OK, lets look at the Store API http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add

    Sample usage:

       myStore.add({some: 'data'}, {some: 'other data'});
    

    The best practice is to also create a Model class . Read the component guides on grid and the data package .

    0 讨论(0)
提交回复
热议问题