2012-07-25 129 views
0

我有Extjs網格組件的問題。如果你看看附帶的屏幕截圖,你會看到兩行JSON數據是正確的。EXTJS網格數據問題

但是,您可以看到附帶的屏幕截圖,ExtJS網格組件僅顯示一條奇怪的問題。我什麼都試過沒有成功:(

這裏是ExtJS的代碼:

數據用戶部段的商店:

var customersStore = new Ext.data.JsonStore({ 
    root: 'customers', 
    baseParams: { action: 'customers'}, 
    proxy: new Ext.data.HttpProxy({ 
     url: '../invoice/grid-master-details.php', 
     method: 'POST' 
    }), 
    fields: ['MetroNo', 'SpecVatNo', 'HomeStoreNo', 'CustShortName', 'StoreName', 'months', 
    { name: 'invtotal', type: 'float' }, 
    { name: 'invcount', type: 'int' }], 
    idProperty: 'MetroNo' 
}); 

網格初始化參數:

Ext.onReady(function() { 
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); 

    function change(val) { 
     if (val > 0) { 
      return '<span style="color:green;">' + val + '</span>'; 
     } else if (val < 0) { 
      return '<span style="color:red;">' + val + '</span>'; 
     } 
     return val; 
    } 

    var customersGrid = new Ext.grid.GridPanel({ 
     title: 'Customer Informations', 
     plugins: new Ext.ux.GridTotals(), 
     renderTo: 'customers-div', 
     store: customersStore, 
     sm: new Ext.grid.RowSelectionModel({ singleSelect: true }), 
     columns: [ 
      { id: 'vat-no', 
       header: "Tax Number", 
       width: 50, 
       dataIndex: 'SpecVatNo', 
       sortable: false, 
       hidden: true 

      }, 
      { id: 'store-name', 
       header: 'Store Name', 
       width: 70, 
       dataIndex: 'StoreName', 
       sortable: true 
      }, 
      { id: 'cust-name', 
       header: 'Customer Title', 
       width: 130, 
       dataIndex: 'CustShortName', 
       sortable: true, 
       totalsText: 'TOTAL' 
      }, 
      { id: 'invoice-count', 
       header: "Invoice Address", 
       width: 40, 
       dataIndex: 'invcount', 
       align: 'right', 
       sortable: false, 
       summaryType: 'sum' 
      }, 
      { id: 'invoice-total', 
       header: "Invoice Total", 
       width: 60, 
       dataIndex: 'invtotal', 
       align: 'right', 
       sortable: false, 
       renderer: Ext.util.Format.CurrencyFactory(true, 2, ",", ".", "TL", true), 
       summaryType : 'sum', 
       roundToPlaces: 3 
      }, 
      { 
       id: 'selected-date', 
       header: "Period", 
       width: 20, 
       dataIndex: 'months', 
       sortable: false, 
       hidden: true 
      }    
     ], 
     autoExpandColumn: 'cust-name', 
     width: 700, 
     height: 240, 
     loadMask: {msg:'Loading customer infos ...'}, 
     stripeRows: true, 
     columnLines:true, 
     stateful: true, 
     stateId: 'customerGrid', 
     viewConfig: { 
      forceFit: true 
     }, 
     tbar: new Ext.Toolbar({ 
      items: [{ xtype: 'tbtext', text: 'Period' }, 
        { xtype: 'tbspacer', width: 10}, 
        { xtype: 'combo', 
          store: datesStore, 
          id: 'monthid', 
          displayField: 'months', 
          valueField: 'dateid', 
          editable: false, 
          mode: 'remote', 
          forceSelection: true, 
          triggerAction: 'all', 
          emptyText: 'Select Period...', 
          selectOnFocus: true 
        }, 
        { xtype: 'tbspacer', width: 15}, 
        { xtype: 'tbseparator'}, 
        { xtype: 'tbspacer', width: 10}, 
        { xtype: 'tbtext', text: 'Tax Number'}, 
        { xtype: 'tbspacer', width: 10}, 
        { xtype: 'textfield', id: 'vatnoid'}, 
        { xtype: 'tbspacer', width: 10}, 
        { xtype: 'button', 
          text: ' Show ', 
          iconCls: 'quicksearch', 
          handler: function() { 
           var mid = Ext.getCmp('monthid').getValue(); 
           var vid = Ext.getCmp('vatnoid').getValue(); 
           customersStore.load({ 
            params: {'months': mid, 'vatno': vid} 
           }); 
          } 
        } 
        ] 
     }) 
    }); 
+1

您的JSON響應中的兩個記錄都包含相同的'MetroNo',您已爲'Model'指定'idProperty'。這是正確的主鍵嗎? – 2012-07-25 13:38:54

+0

是的,我正在使用基於StoreName的分組。 – 2012-07-25 13:44:12

+0

你是男人,非常感謝你。我解決了。 – 2012-07-25 13:48:43

回答

2

於底層ModelidProperty被指定爲MetroNo,爲每個記錄在JSON響應中返回其不是唯一的。

idProperty更改爲每個記錄唯一的字段。