javascript 从网格 ExtJs 4 中获取一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14724732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
get a row from a grid ExtJs 4
提问by Marco
I think it's very simple to answer to this question:
我认为回答这个问题很简单:
I have simple grid with my custom store:
我的自定义商店有简单的网格:
//other code
{
xtype: 'grid',
store: 'SecondStore',
itemId: 'mainTabPanel2',
columns: [
//this is not from the store
{
header: 'Not Form Store',
id: 'keyId2',
},
//from the store
{
header: 'From Store',
dataIndex: 'label',
id: 'keyId',
}
]
}
the store only populate the second column with id: keyId. In fact it have:
商店只用 id:keyId 填充第二列。事实上它有:
fields: [{ name: 'label' }]
And this work well.
这工作得很好。
I want to get from a function the row n°1 of this grid.
我想从函数中获取此网格的第 1 行。
handler: function() {
var grid = Ext.ComponentQuery.query('grid[itemId="mainTabPanel2"]')[0];
//var row= get row(1) <- i don't know how to get the complete row
}
I'm working with ExtJs 4 so i can't get it with the command grid.getView().getRow(1);
我正在使用 ExtJs 4,所以我无法使用命令获取它 grid.getView().getRow(1);
I can't get it from the store because i want to get also the content of the column with id:keyId2 that is not stored in the store, so I can't do something like:
我无法从商店中获取它,因为我还想获取未存储在商店中的 id:keyId2 列的内容,因此我无法执行以下操作:
grid.getStore().getAt(1);
Anyone know how to get the complete row in ExtJs 4? Thank you!
有人知道如何在 ExtJs 4 中获得完整的行吗?谢谢!
采纳答案by Marco
I've solved accesing the DOM:
我已经解决了访问 DOM:
/* Get Dom of the first grid */
var DOMgrid = Ext.select('#'+gridview.getId());
var gridChild = DOMgrid.elements[0].children[1].children[0].children;
Then you should get the "children" you are interested to simply following the DOM structure.
然后你应该得到你感兴趣的“孩子”,只需遵循 DOM 结构。
You can also get the singleton flyweight element applying the Ext.fly()
comand and update the content with the update()
comand:
您还可以获取应用Ext.fly()
命令的单例享元元素并使用命令更新内容update()
:
Ext.fly(/*DOM object here*/).update(/*raw content here*/)
回答by mustafa.0x
回答by Afshin Mehrabani
I think you need something like this:
我认为你需要这样的东西:
Ext.onReady(function () {
var store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'email', 'phone'],
data: {
'items': [{
'name': 'Lisa',
"email": "[email protected]",
"phone": "555-111-1224"
}, {
'name': 'Bart',
"email": "[email protected]",
"phone": "555-222-1234"
}, {
'name': 'Homer',
"email": "[email protected]",
"phone": "555-222-1244"
}, {
'name': 'Marge',
"email": "[email protected]",
"phone": "555-222-1254"
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
alert(grid.getStore().getAt(1).data.name);
});
jsFiddle: http://jsfiddle.net/RftWF/
jsFiddle:http: //jsfiddle.net/RftWF/
回答by Ankit
Get FireBug plugin and monitor the grid at 'handler'. If you see the data from the column keyId2 than you can see the way in the firebug too. i.e grid object->store object-> data array.
获取 FireBug 插件并在“处理程序”处监视网格。如果您从 keyId2 列中看到数据,那么您也可以看到萤火虫中的方式。即网格对象->存储对象->数据数组。
Can you tell us how did you add data in the column keyId2 of the grid ?
你能告诉我们你是如何在网格的 keyId2 列中添加数据的吗?