PDA

View Full Version : MoveNext MoveLast MovePrevious and MoveFirst not working first time



sabarigirish
21 Nov 2016, 1:35 AM
Hi,


We have a cfgrid with pagingtoolbar and have overridden the MoveFirst.MovePrevious,MoveNext and MoveLast methods of the grid.When the grid is loaded first time these methods are not firing.If Move Next is clicked then onwards MoveNext is firing and all other methods are firing.We are using Ext JS 4.0

the code is as given below:

Ext.PagingToolbar.override
({



moveNext : function(){
// alert("movenext");
document.workingBillDetailsForm.txtGridOp.value="MN";

var me = this;
store = me.store;
// total = me.getPageData().pageCount,
var total=Math.ceil(store.getTotalCount() / me.pageSize);
/*
var fromRecord = (( ((Math.ceil((this.cursor+this.pageSize)/this.pageSize)) - 1) * this.pageSize) -(Math.ceil((this.cursor+this.pageSize)/this.pageSize))) + 2;
*/

var currentPage = Math.ceil((this.cursor + this.pageSize)/this.pageSize);


//alert(fromRecord);
// total = 144;
//next = store.currentPage + 1;
var next = currentPage+1;
var startRec=(currentPage * this.pageSize);



if (next <= total) {

if (me.fireEvent('beforechange', me, next) !== false) {

store.load({
params:{
page: next,


start: startRec,


limit: this.pageSize


},


callback: function(documents, options, success){


if (success == false) { // Timeout


Ext.MessageBox.alert('alert', 'timeout');


}


}


});


return true;
}
}
return false;
},


moveLast : function(){

var me = this;
store = me.store;
var last = Math.ceil(store.getTotalCount() / me.pageSize);
var startRec=(last-1) * this.pageSize;

if (me.fireEvent('beforechange', me, last) !== false) {

store.load({
params:{
page: last,


start: startRec,


limit: this.pageSize


},


callback: function(documents, options, success){


if (success == false) { // Timeout


Ext.MessageBox.alert('alert', 'timeout');


}


}


});
return true;
}
return false;
},
movePrevious : function(){

//alert('MovePrevious');
document.workingBillDetailsForm.txtGridOp.value="MP";


var me = this,
store = me.store;
// total = me.getPageData().pageCount,
var total=Math.ceil(store.getTotalCount() / me.pageSize);
/*
var fromRecord = (( ((Math.ceil((this.cursor+this.pageSize)/this.pageSize)) - 1) * this.pageSize) -(Math.ceil((this.cursor+this.pageSize)/this.pageSize))) + 2;
*/

var currentPage = Math.ceil((this.cursor + this.pageSize) /this.pageSize);


//alert(fromRecord);
// total = 144;
//next = store.currentPage + 1;
var prev = currentPage-1;
var startRec=(prev * this.pageSize)-this.pageSize;

if (prev > 0) {
//alert('inside1');
if (me.fireEvent('beforechange', me, prev) !== false) {
// store.loadPage(3);

//store.nextPage();
store.load({
params:{
page: prev,


start: startRec,


limit: this.pageSize


},


callback: function(documents, options, success){


if (success == false) { // Timeout


Ext.MessageBox.alert('alert', 'timeout');


}


}


});


return true;
}
}
return false;
},
moveFirst : function(){

var me = this,
store = me.store;
if (this.fireEvent('beforechange', this, 1) !== false){
store.load({
params:{
page: 1,


start: 0,


limit: this.pageSize


},


callback: function(documents, options, success){


if (success == false) { // Timeout


Ext.MessageBox.alert('alert', 'timeout');


}


}


});
return true;
}
return false;
}


});

tristan.lee
22 Nov 2016, 2:49 PM
Please wrap your code so that it is readable.

If the methods are not called when the grid is first loaded, that sounds expected since you haven't clicked on them yet. You mention once you click on the icon, then it works going forward. What is your expectation?

sabarigirish
22 Nov 2016, 11:13 PM
Hi
When the grid is fully loaded and when the user clicks the first time on MoveNext and Move Last buttons these methods are not getting fired
When the user clicks second time then the methods fire.We have put alerts on the overridden methods as given below.The alerts are firing when the user clicks second time i.e when the user is on the second page.
The code is as given below:

Ext.PagingToolbar.override
({


moveNext : function(){
alert("movenext");
document.workingBillDetailsForm.txtGridOp.value="MN";


var me = this;
store = me.store;


var total=Math.ceil(store.getTotalCount() / me.pageSize);


var currentPage = Math.ceil((this.cursor + this.pageSize)/this.pageSize);


var next = currentPage+1;
var startRec=(currentPage * this.pageSize);




if (next <= total) {


if (me.fireEvent('beforechange', me, next) !== false) {


store.load({
params:{
page: next,
start: startRec,
limit: this.pageSize
},


callback: function(documents, options, success){
if (success == false) { // Timeout
Ext.MessageBox.alert('alert', 'timeout');
}
}
});


return true;
}
}
return false;
},




moveLast : function(){
alert("movelast");
var me = this;
store = me.store;
var last = Math.ceil(store.getTotalCount() / me.pageSize);
var startRec=(last-1) * this.pageSize;


if (me.fireEvent('beforechange', me, last) !== false)
{
store.load({
params:{
page: last,
start: startRec,
limit: this.pageSize
},


callback: function(documents, options, success)
{
if (success == false) { // Timeout
Ext.MessageBox.alert('alert', 'timeout');
}
}
});
return true;
}
return false;
}
});

sabarigirish
23 Nov 2016, 11:37 PM
Hi
When the grid is fully loaded and when the user clicks the first time on MoveNext and Move Last buttons these methods are not getting fired but it is going to the next page (alerts are not firing)
When the user clicks second time then the methods fire.We have put alerts on the overridden methods as given below.The alerts are firing when the user clicks second time i.e when the user is on the second page.
The code is as given below:

Ext.PagingToolbar.override
({


moveNext : function(){
alert("movenext");
document.workingBillDetailsForm.txtGridOp.value="MN";


var me = this;
store = me.store;


var total=Math.ceil(store.getTotalCount() / me.pageSize);


var currentPage = Math.ceil((this.cursor + this.pageSize)/this.pageSize);


var next = currentPage+1;
var startRec=(currentPage * this.pageSize);




if (next <= total) {


if (me.fireEvent('beforechange', me, next) !== false) {


store.load({
params:{
page: next,
start: startRec,
limit: this.pageSize
},


callback: function(documents, options, success){
if (success == false) { // Timeout
Ext.MessageBox.alert('alert', 'timeout');
}
}
});


return true;
}
}
return false;
},




moveLast : function(){
alert("movelast");
var me = this;
store = me.store;
var last = Math.ceil(store.getTotalCount() / me.pageSize);
var startRec=(last-1) * this.pageSize;


if (me.fireEvent('beforechange', me, last) !== false)
{
store.load({
params:{
page: last,
start: startRec,
limit: this.pageSize
},


callback: function(documents, options, success)
{
if (success == false) { // Timeout
Ext.MessageBox.alert('alert', 'timeout');
}
}
});
return true;
}
return false;
}
});

Gary Schlosberg
29 Nov 2016, 7:46 AM
If your grid is created by ColdFusion, it is not supported to use Ext JS PagingToolbar on it.

sabarigirish
5 Dec 2016, 12:45 AM
Hi Gary,
Thanks for the reply
Everything is working fine with the pagingtoolbar except the first time
first time MovePrevious,MoveLast or MoveNext is not firing after any other operation
everything is working fine

sabarigirish
5 Dec 2016, 12:49 AM
This is not happening the first time only so not able to find out whether MovePrevious or MoveNext or MoveLast is clicked