PDA

View Full Version : Json without result



wki01
19 May 2010, 11:40 PM
{
"success": true,
"results": "-1",
"rows": [
{
"$2":"VEN7TRHKA711358",
"$38":"=====",
"$25":"==",
"$24":"==========",
"$27":"I111"
.....
}
]
}
My server is not able to provide in advance the number of records in my request.
So I put the "results" field to -1.
I'd like to know if the grids provide management of paging without knowing in advance the total number of records.
(I can imagine that the total record is only for viewing the total number of pages (to be given up easily))

Thanks

Condor
20 May 2010, 1:04 AM
You would have to extend the PagingToolbar to support this.

Try:

Ext.ns('Ext.ux');
Ext.ux.NoMaxPagingToolbar = Ext.extend(Ext.Toolbar, {
displayMsg : 'Displaying {0} - {1}',
initComponent: function(){
Ext.ux.NoMaxPagingToolbar.superclass.initComponent.call(this);
this.afterTextItem.hidden = true;
this.last.hidden = true;
},
onLoad : function(store, r, o){
if(!this.rendered){
this.dsLoaded = [store, r, o];
return;
}
var p = this.getParams();
this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
var d = this.getPageData(), ap = d.activePage, lp = d.lastPage;
this.inputItem.setValue(ap);
this.first.setDisabled(ap == 1);
this.prev.setDisabled(ap == 1);
this.next.setDisabled(lp);
this.last.setDisabled(true);
this.refresh.enable();
this.updateInfo();
this.fireEvent('change', this, d);
},
getPageData : function(){
var count = this.store.getCount();
return {
activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
lastPage : count < this.pageSize
};
},
changePage : function(page){
this.doLoad(Math.max(0, (page - 1) * this.pageSize);
},
onPagingKeyDown : function(field, e){
var k = e.getKey(), d = this.getPageData(), pageNum;
if (k == e.RETURN) {
e.stopEvent();
pageNum = this.readPage(d);
if(pageNum !== false){
pageNum = Math.max(1, pageNum) - 1;
this.doLoad(pageNum * this.pageSize);
}
}else if (k == e.HOME){
e.stopEvent();
field.setValue(1);
}else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
e.stopEvent();
if((pageNum = this.readPage(d))){
var increment = e.shiftKey ? 10 : 1;
if(k == e.DOWN || k == e.PAGEDOWN){
increment *= -1;
}
pageNum += increment;
field.setValue(pageNum);
}
}
},
moveLast: Ext.emptyFn
});
(warning: completely untested code)

wki01
20 May 2010, 2:05 AM
Might be an improvement for the next version.
I guess there are many server-side systems that are unable to return the total records.

Thanks

CrazyEnigma
20 May 2010, 5:56 AM
It kind of defeats the purpose of the paging toolbar, doesn't it. Most, if not all, server-side systems are able to return the total records. They just might not be efficient or easy to do.

wki01
20 May 2010, 8:20 AM
I told easy to avoid having to make long explanations.

Even Lotus Domino (my server) can return the total number of records before a request (actually it is also optional).

But if in the view (table) there are 3 million records, the server takes about 20 seconds more of processing only to return the total number.
Until about 200,000 records are no problem.

I believe this implementation is useful, even as a plugin if someone wants to accomplish.
(Unfortunately my limited knowledge of ExtJS does not allow me time to implement it yourself)

Thanks

wki01
23 May 2010, 11:21 PM
The maximum would have PagingToolBar where the number of records comes from the server asynchronously in order to use straight away without having to wait for the server to calculate the total record.

I think it's important for an implementation like me who works in a multinational company where the volumes of the order of millions of records.

Thank you.

joeri
8 Jun 2010, 12:27 AM
You can always "fake" a total. Return 10 million as total, and hide the page count. If the user navigates too far (no rows found), calculate the real total and return that instead.