2017-08-24 70 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