我是Ext JS的新手。我正在使用一个网格面板,在该面板中,当我选择/单击任何行时,网格下方的面板中将显示与所选行相关的某些数据。另外,当窗口加载时,默认情况下应该选择/突出显示第一个窗口。 目前网格&面板显示正常。即使与选定行相关的数据显示在面板中,但该行仍未突出显示。我尝试了grid.focusRow(0)
& grid.getRow(0).highlight()
方法,但它们不起作用。以下是我的代码。在ExtJS中突出显示/选择网格行
//the js file code
initComponent : function() { //within the window instance
var single = false;
var store = new Ext.data.XmlStore({//all necessary fields added}); //store
HttpUtil.syncCall(this.url, "GET", this.loadStore, store,this);
var acctTplMarkup = [//the fields here are displayed on row selection ];
/*The template for displaying the details of the selected row */
this.acctTpl = new Ext.Template(acctTplMarkup);
//check for request type, if type is range of checks create the grid
if (single == false) {
var gridView = new Ext.grid.GridView();
var colModel = new Ext.grid.ColumnModel([ {
header : 'Status',
dataIndex : 'status'
}, {
header : 'Message',
dataIndex : 'message'
} ]);
var selModel = new Ext.grid.RowSelectionModel({
singleSelect : true
});
grid = new Ext.grid.GridPanel({
...
listeners : {
render : function(grid) {
Ext.getCmp('check').store.on('load',function(store, records, options) { //check is the id value for the window instance
grid.getSelectionModel().selectFirstRow();
});
}
}
}); //gridPanel
} //if
/* If request type is range select then display the grid */
...
if (single == false) {
grid.getSelectionModel().on('rowselect', function(sm, rowIdx, r) {
Ext.getCmp('check').acctTpl.overwrite(Ext.getCmp('detailPanel').body, r.data);
}); //rowselect
} //if
Ext.apply(this, {
...
listeners : {
'afterrender' : function(){
Ext.getCmp('check').acctTpl.overwrite(Ext.getCmp('detailPanel').body, this.store.getAt(0).data,true);
}
}
});
Check.superclass.initComponent.apply(this, arguments);
}, //initComponent
从数据存储中的数据被加载&正常显示,但只是该行不突出。谁能告诉我我错了哪里?
嗨,感谢您的回复。我已经尝试过这些方法,但他们不工作。我的网格已完成,但不知何故,我无法突出第一行。有没有其他方法? – 2012-01-04 11:52:56
你提到的方法有错误吗? 所有可能的解决方法将在未来给您带来额外的问题,因此您最好在尝试任何自制之前尝试获取现有的方法。 – Li0liQ 2012-01-04 15:42:45
'getView()。getRow'在ExtJS 4中不存在;使用'getView()。getNode'。 – 2013-10-31 11:29:07