2013-10-07 4 views
1

Я пытаюсь добавить строки в свою сетку.Добавление пустой строки в сетку

Я видел пример в документации:

onAddRouteClick: function(){ 
// Create a model instance 
var rec = new KitchenSink.model.grid.Plant({ 
    buying_vendor_id: 12, 
    country_code: '1', 
    route: 0 
}); 

this.getStore().insert(0, rec); 
this.cellEditing.startEditByPosition({ 
    row: 0, 
    column: 0 
}); 

}

this.getStore().insert(0, rec); 
this.cellEditing.startEditByPosition({ 
    row: 0, 
    column: 0 
}); 
} 

Но я не могу показаться, чтобы заставить его работать в своем коде.

Это моя сетка:

onBtnRoutesSearchClick: function(button, e, options){ 
    var me = this; 
    var v_url = 'GetRoutes.jsp?' + Ext.urlEncode({'route_id': routeID, 'route_country_code' : routeCountryCode , 'route_vendor_id' : routeVendorID}); 

    var newTab = Ext.create('Ext.panel.Panel', { 
    id: 'routes_pannel', 
    title: 'Routes', 
    autoScroll: true, 
    layout: { 
     type: 'fit' 
    }, 
    closable: true, 
    dockedItems: [ 
     { 
      xtype: 'toolbar', 
      dock: 'top', 
      items: [ 
       { 
        xtype: 'button', 
        id: 'buttonResetBid', 
        icon: 'images/Plus.png', 
        text: 'Add Row', 
        listeners: { 
         click: { 
          fn: me.onAddRouteClick, 
          scope: me 
         } 
        } 
       } 
      ] 
     } 
    ], 
    items: [{ 
     id: 'routes_grid', 
     xtype: 'gridpanel', 
     autoShow: false, 
     autoScroll: true, 
     store: Ext.create('Ext.data.Store', { 
      fields:[ 
      {name: 'buying_vendor_id', type: 'int', sortType: 'asInt'}, 
      {name: 'country_code', type: 'int', sortType: 'asInt'}, 
      {name: 'route', type: 'int', sortType: 'asInt'} 
      ], 
      proxy: { 
       type: 'ajax', 
       timeout: 120000, 
       url: v_url, 
       reader: { 
        type: 'json', 
        root: 'data', 
        successProperty: 'success' 
       } 
      }, 
      autoLoad: true 
     }), 
     columns: [ 
      { 
       xtype: 'gridcolumn', 
       dataIndex: 'buying_vendor_id', 
       width: 100, 
       text: 'Buying Vendor' 
      }, 
      { 
       xtype: 'gridcolumn', 
       dataIndex: 'country_code', 
       width: 100, 
       text: 'Country Code' 
      }, 
      { 
       xtype: 'gridcolumn', 
       dataIndex: 'route', 
       width: 80, 
       text: 'Route' 
      } 
     ], 
    }] 
}); 

var panel = Ext.getCmp("MainTabPanelID"); 
panel.add(newTab).show(); 
+2

Что означает «Не могу заставить его работать "означает? Что происходит? Что вы ожидаете? Вызываются ли какие-либо ошибки? Какую отладку вы сделали? –

+0

Он должен иметь строку в сетке. «OnAddRouteClick» был взят как пример. obviusly rec = KitchenSink.model.grid.Plant s не currect для моего кода, и это приводит к ошибке, которая не определена. Итак, моя проблема - basicy, что должно быть «rec» определено как? – susparsy

ответ

2

Таким образом, вы пытаетесь add запись в store правой? ОК, давайте посмотрим на Store API http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add

Пример использования:

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

Лучшая практика является также создать класс модели. Прочтите компонент guides на сетке и data package.

3

1.Create ваша модель

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

2.Create ваш RowEditing

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

3.Get магазин и создать сетку

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') 
}); 
Смежные вопросы