2017-08-24 68 views
-1

我有一個表單,我需要用字段值填充一個網格。用從表單中獲取的值填充網格? EXTJS

在這一刻,組合框值通過PHP文件中的SQL查詢獲得,由JSON Store調用以填充表單。

與我使用填充網格數據的方式相同,但只與其他網格存儲。

其實我用JSON方法填充網格。

這是我的JSON商店,調用一些填充在網格中的值。

var store_grid_CC = new Ext.data.JsonStore({ 
//successProperty: 'success', 
url: 'json/distribucion.php?opcion=grid', 
autoLoad: true, 
fields : ['center_name', 'subcenter_id','subcenter_name', 'porc_distribucion'], 
root : 'grid', 
}); 

,並在下拉列表收聽我使用這個調用(當我在組合中選擇一個值,因爲電網應填)加載電網

store_grid_CC.load({ 
params:{ subcenter_id: subcenter_id, 
opcion:'grid'} 
}); 

那家商店去distribucion.php併發送從組合框中獲得的subcenter_id,然後由SQL返回的PHP文件查詢填充在網格的前2列(是4)中的center_name和subcenter_name。

但最後2列應填寫從表單中的文本字段獲得的一些數據。

然後我的問題是,我有2種方法來獲取這個網格的數據,(通過JSON方式和價值形式的方式)。

我認爲的一個解決方案是從表單字段獲取所有數據,包括組合框值,但不調用SQL並等待JSON響應,否則,從de組合字段獲取RawValue(最終值,不使用一個subcenter_id)。

實例:組合框的值時調用:

form.getForm().findField('combobox').RawValue() that return a name. 

並與文本框:

form.getForm().findField('textfield').getValue() that return a number. 

GRID:

 column1   column2  column3    column4 

ROW1 comboRawValue comboRawValue texfieldgetValue texfieldgetValue


ROW2 「汽車」, 「貨車」 20 100


(僅是一例)。

我需要把這個數據放到網格存儲中,當我按下按鈕(添加行)時,這個值應該插入到一個新行的網格中。

我該怎麼做?,另外,我怎樣才能從表格中獲得的數據填充網格商店?

我試圖與SimpleStores,JSONStores,但我不知道如何給窗體值存儲以後網格readed。我沒有成功。

非常感謝!

回答

1

步驟1:您希望爲表單字段使用與您的網格列和存儲字段相同的名稱。

E.g.表格字段:

items: [{ 
    xtype: 'textfield', 
    fieldLabel: 'Test string', 
    name: 'Test1' 
},{ 
    xtype: 'checkbox', 
    fieldLabel: 'Test bool', 
    name: 'Test2' 
},{ 
    xtype: 'numberfield', 
    fieldLabel: 'Test number', 
    name: 'Test3' 
}] 

例如,型號字段:

Ext.define('MyModel',{ 
    extend: 'Ext.data.Model', 
    fields:[{ 
     name: 'Test1', 
     type: 'string' 
    },{ 
     name: 'Test2', 
     type: 'bool' 
    },{ 
     name: 'Test3', 
     type: 'int' 
    }] 
}); 

例如, Grid列:

columns:[{ 
    xtype: 'gridcolumn', 
    text: 'Test string', 
    dataIndex: 'Test1' 
},{ 
    xtype:'checkcolumn', 
    text: 'Test bool', 
    dataIndex: 'Test2' 
},{ 
    xtype: 'numbercolumn', 
    text: 'Test number', 
    dataIndex: 'Test3' 
}] 

第2步:將記錄綁定到表單。

當創建一個新條目,創建一個新的模型實例,並將其綁定到窗體:

form.setRecord(Ext.create('MyModel')) 

保存時,更新的記錄,並將其添加到存儲,如果它是不是已經。

form.updateRecord(); 
if(store.indexOf(form.getRecord()==-1) store.add(form.getRecord()); 

當編輯現有條目,記錄綁定到店,比如第五記錄:

form.setRecord(store.getAt(4)); 
+0

謝謝亞歷山大,那可與EXTJS 4?我提出這個問題是因爲我沒有使用模型文件(如extjs6),只有我使用Simple和JSON Stores,最近我學習了EXTJS。 – Camilo

+0

那麼,在ExtJS 4中,甚至需要模型,而在ExtJS6中,大多數商店都可以在沒有模型的情況下工作。 – Alexander