PDA

View Full Version : How to get the total no.of rows in a Paging Grid?



saasira
23 Apr 2007, 9:22 AM
Hi!Everybody,

I need to hide the Grid tool bar if the no.of rows returned by a remote Servlet is less than the pageSize.I'm able to hide the toolBar , but how to get the total rows of data available to the grid?

I tried using :



grid.dataModel.getTotalRowCount();


It's working fine in a static grid , but is returning zero in case of Paging Grid!

How to know the no. of rows of data sent by the Server when a grid is loaded dynamically?

Thanks in advance,
Regards,
Samba

tryanDLS
23 Apr 2007, 10:11 AM
You're still using .33 - you should upgrade - support is going to be pretty thin for .33 at this point. Did you pass back a totalProperty as defined in your schema?

saasira
23 Apr 2007, 11:22 AM
Yes,tryan.I have set the totalProperty along with the data in the JSON response I'm sending through a servlet.But ,yet it's giving 0 for dataModel.getTotalRowCount(),even when called after loading the data.

And regarding the Upgrad, Yes,I will soon do that.
Thanking you ,
Samba

tryanDLS
23 Apr 2007, 11:46 AM
I would suggest you set BPs in loadableDataModel.processResponse and see if the data is getting populated correctly.

sonic64
23 Apr 2007, 11:47 AM
if ds is your datastore and totalcount is the total of your records in your json Data, then ds.reader.jsonData.totalCount should give you the total count.

tryanDLS
23 Apr 2007, 12:11 PM
if ds is your datastore and totalcount is the total of your records in your json Data, then ds.reader.jsonData.totalCount should give you the total count.

That syntax doesn't apply pre-1.0

sonic64
23 Apr 2007, 1:13 PM
Tim,

I did use it with Ext 1 Beta 2

tryanDLS
23 Apr 2007, 7:34 PM
I did use it with Ext 1 Beta 2
Pre-1.0 means before 1.0, regardless of whether it was alpha or beta. That syntax does not exist in .33 which the OP is using.

saasira
24 Apr 2007, 8:45 AM
Thank you for your suggestions,But I could not get that working.

The data is getting populated correctly,but When dm.getTotalRowCount() is called ... it is returning zero,where the total property is expected.

Or , is there a way to get the total rows loaded(not the pageSize,for sometimes the rows loaded may be lesser than the pageSize specified in a paging Grid)?

Thanking you,
Samba.

tryanDLS
24 Apr 2007, 9:53 AM
Did you debug as I said in my first post? You need to look at the response and see what's happening.

saasira
24 Apr 2007, 11:33 AM
Hi Trian, As you have asked I'm pasting the response from the servlet:

It is clearly printing the totalProperty...as shown below:

{"respdetails":[{"Status":true,"Path":"http://psvn/","FunctionName":"LOCK","RepositoryName"

:"svnrep"},{"Status":false,"Path":"http://psvn/","FunctionName":"MOVE","RepositoryName":"rep"

},{"Status":true,"ExceptionPath":"http://psvn/","FunctionName":"RESOLVE","RepositoryName":"rep"}]

,"TotalCount":3}


And it is populating the three rows in the grid, but when I call dm.getTotalRowCount() it is returning zero.... what I needed is If the total count is less than ,say 10... (the pageSize), hide the toolbar used for paging.

any idea?
Thanking you ,
regards,
Samba

tryanDLS
24 Apr 2007, 11:51 AM
What you cut and paste from your response isn't helpful. YOU need to debug thru the code the figure out why your response isn't being handled the way you think it should be. Set breakpoints and step thru the code - that's what a programmer does. If you are unwilling to make the effort, you're not going to get very far solving problems. Obviously, if the total count is 0, you have an error - you should also examine you reader creation to see if it's correct - there are numerous threads/examples regarding this.

saasira
29 Apr 2007, 1:18 AM
Hello tryan, I got the total row count of the grid as follows;




var grid = new YAHOO.ext.grid.Grid('example-grid', dataModel, colModel);

grid.autoWidth = true;

grid.autoHeight = true;

grid.render();



//dataModel.loadData(data);




dataModel.load('../../../../jsonservlet');


var rowcount;

dataModel.on('load', function(){

alert( "############"+dataModel.getTotalRowCount()+"##########" );

rowcount=dataModel.getTotalRowCount();

alert("After loading data"+rowcount);// returns loaded rows

});

/* alert("Regular flow "+rowcount);
// returns zero again because this called before load.






Thanking you ,
Regards,
Samba.

6epcepk
6 Dec 2007, 11:59 PM
if ds is your datastore and totalcount is the total of your records in your json Data, then ds.reader.jsonData.totalCount should give you the total count.
From current version: ds.reader.jsonData.total

innovator
27 Nov 2008, 1:28 AM
Hi, i am using a grid with store and column model defined below.
My prob is i want to use the total no of records in the column model renderer. But before store's load column model's renderer is called so unable to set the total count value which is needed in the renderer function.
Plz help me out.



var totalrec;
var myReader = new Ext.data.JsonReader({

root: 'items',
totalProperty: 'total',
fields: [
{name: 'roleName',type:'string'},
{name: 'permissions'}
]
}),


store = new Ext.data.GroupingStore({
proxy:new Ext.data.HttpProxy({url:'managerole.html'}),
baseParams : {action:'load'},
reader: myReader,
sortInfo:{field: 'roleName', direction: "ASC"},

groupField:'roleName'
});

store.on('loadexception', function(){

alert('ds load exception occured');
});


store.on('load', function() {
alert("00");
var noOfRec = store.getTotalCount();
alert("after load="+noOfRec);
totalrec = noOfRec;


});

store.load();

function renderPermission1(value,meta,rec,rowIndex,colIndex,st){

alert(totalRec);



}
grid = new xg.GridPanel({
sm:sm,
id:'grid',
ds:store,
title:'Manage Role',

columns: [
sm,
{header: "Role",width: 13, sortable: false, dataIndex: 'roleName', renderer:tes},
{ header:'',width: 20, sortable: false, renderer: renderPermission1,dataIndex: 'permissions'},

],

view: new Ext.grid.GroupingView({
checkboxToggle:true,
forceFit:true,
groupTextTpl: '{text}' ,
showGroupName: false
}),
buttons: [{
text:'Save'
//,handler:saveFun
},{
text:'Add'
},{
text:'Delete'
//,handler:deleteFun
}],
buttonAlign:'right',

frame:true,
width: 700,
autoHeight:true,
animCollapse: false,
renderTo:'list'
});