newedge
18 Sep 2009, 8:35 PM
Just wanted to post this little bit of code we did recently. I couldn't find a way to have our grid return a nice message stating that no records were found.
You will need to add a class x-grid3-body-empty with something like
.x-grid3-body-empty{
height:30px;
margin-top:10px;
font-size:12px;
text-align:center;
color:#888888;
}
And then just extend the grid to something like this. Notice you can customize what you want the message to be using emptyMsg when configuring your grid.
ExtendedGrid = Ext.extend(Ext.grid.GridPanel, {
initComponent: function() {
ExtendedGrid.superclass.initComponent.call(this);
},
emptyMsg:"There are no records available",
onRender: function (g) {
ExtendedGrid.superclass.onRender.call(this,g);
this.store.addListener("load",function(store,records,options){
//returns the element for x-grid3-body for the current grid
//ensures safe for multiple grids per page
el = Ext.query(".x-grid3-body",this.body.id)[0];
if(records.length==0){
el.innerHTML = this.emptyMsg;
el.className = "x-grid3-body x-grid3-body-empty";
}else{
el.className = "x-grid3-body";
}
},this);
}
});
Please let us know if you guys have a better way or better yet if the grid will do this when store returns no records and we just missed it.
You will need to add a class x-grid3-body-empty with something like
.x-grid3-body-empty{
height:30px;
margin-top:10px;
font-size:12px;
text-align:center;
color:#888888;
}
And then just extend the grid to something like this. Notice you can customize what you want the message to be using emptyMsg when configuring your grid.
ExtendedGrid = Ext.extend(Ext.grid.GridPanel, {
initComponent: function() {
ExtendedGrid.superclass.initComponent.call(this);
},
emptyMsg:"There are no records available",
onRender: function (g) {
ExtendedGrid.superclass.onRender.call(this,g);
this.store.addListener("load",function(store,records,options){
//returns the element for x-grid3-body for the current grid
//ensures safe for multiple grids per page
el = Ext.query(".x-grid3-body",this.body.id)[0];
if(records.length==0){
el.innerHTML = this.emptyMsg;
el.className = "x-grid3-body x-grid3-body-empty";
}else{
el.className = "x-grid3-body";
}
},this);
}
});
Please let us know if you guys have a better way or better yet if the grid will do this when store returns no records and we just missed it.