You need to sign in to do that
Don't have an account?
visualforce_dev
previous next navigation in datatable
can anybody help me.
I have to display say 100 rows in a table view, limit 10.
after clicking next it will display 10-20 like that.
Previous will do the reverse.
Updated code for pagination http://wiki.apexdevnet.com/index.php/Pagination
http://wiki.apexdevnet.com/index.php/Pagination
All Answers
1. You have a large list of data.
2. Create a second list that has a set size of ten.
3. Create a integer that will be your "index".
4. The first time the page loads add 0-9 of the large list to your list of 10, set "index" to 0.
5. On the page have two buttons that call two different methods.
6. For Next add 10 to the "index" and use this as the starting index of the large set. Clear the small set. Have a for loop that increments 10 times getting the index of the large list and adding it to the small list.
7. For the Previous button subtract 10 from the "index" variable. Clear the small set. Have a for loop that increments 10 times getting the index of the large list and adding it to the small list.
8. You will also need some controlling if statements to check when the "index" goes below 0 and above the size of the large list.
Hope that wasn't too confusing.
Message Edited by TehNrd on 06-16-2008 10:25 PM
Thanks for ur idea,
the idea is clear, but as I am new to this I dont know upto what level it will work.
External entry point
Account[] subresults;
for(Integer i=0;i<5;i++)
{
subresults[i]=results[i];
I tried ur code. It s giving the same error
System.NullPointerException: Attempt to de-reference a null object
External entry point
The code is like that only. The query is returning values(more that 20 rows)
if we trying to assign
subresults=results;
it is working, but we have to divide the main array.
Message Edited by visualforce_dev on 06-17-2008 09:13 PM
Please use the following code for the paging.
This is working fine, if you developed in some other way please let me know.
public class paging {
string searchtext;
List<Bill_To_Customer__c> getlbtc;
List<Bill_To_Customer__c> g = new List<Bill_To_Customer__c>();
List<Bill_To_Customer__c> g1 = new List<Bill_To_Customer__c>();
Integer i = 10;
Integer j = 0, k = 0, flag = 0;
public void setstr(String s){searchtext = s;}
public String getstr(){return searchtext;}
public PageReference getbtc()
{
g.clear();
getlbtc=[select Bill_To_Cust_No__c,Cust_Name__c,Cust_Type__c,Country__c, Cust_Price_Type__c from Bill_To_Customer__c where Bill_To_Customer__c.Cust_Name__c like : searchtext+'%' order by Bill_To_Cust_No__c];
if(getlbtc.size()>10)
for(i=0;i<10;i++)
g.add(getlbtc[i]);
else
g = getlbtc;
return null;
}
public List<Bill_To_Customer__c> next()
{
Integer temp = 0;
if(getlbtc.size()>10)
{
if(i < getlbtc.size())
{
g.clear();
i = i+10;
for(j=j+10;j<i;j++)
if(j < getlbtc.size())
{
g.add(getlbtc[j]);
temp++;
}
else
break;
j = j-10;
}
getGetlbtc();
}
else
g = getlbtc;
if((temp!=10)&&(flag==0))
{
j = j-temp+10;
flag = 1;
system.debug('temp j:'+j);
}
return null;
}
public PageReference prev()
{
Integer y=9,x=0;
g1.clear();
if(getlbtc.size()>10)
{
if(j>0)
{
g.clear();
//for(k=j-1;K>j-11;K--)
k = j-1;
Integer a = j-1;
System.debug('hiiiiiii'+k);
if(k>=0)
{
for(k=a;k>j-11;k--)
g.add(getlbtc[k]);
g1 = g.deepclone();
for(x=0;x<10;x++)
{
system.debug('g.get(x)'+g.get(x));
g1.set(y,g.get(x));
system.debug('g.get(y)'+g.get(y));
y--;
}
g = g1;
}
else{}
i = j;
j = j-10;
}
getGetlbtc();
}
else
g = getlbtc;
return null;
}
public List<Bill_To_Customer__c> getGetlbtc() {
return g;
}
}
This is latest version of the paging controller.
public class paging1 {
string searchtext;
List<Bill_To_Customer__c> getlbtc;
List<Bill_To_Customer__c> g = new List<Bill_To_Customer__c>();
Integer i = 10;
Integer j = 0, k = 0, flag = 0;
public void setstr(String s){searchtext = s;}
public String getstr(){return searchtext;}
public PageReference getbtc()
{
g.clear();
getlbtc=[select Bill_To_Cust_No__c,Cust_Name__c,Cust_Type__c,Country__c, Cust_Price_Type__c from Bill_To_Customer__c where Bill_To_Customer__c.Cust_Name__c like : searchtext+'%' order by Bill_To_Cust_No__c];
if(getlbtc.size()>10)
for(i=0;i<10;i++)
g.add(getlbtc[i]);
else
g = getlbtc;
return null;
}
public List<Bill_To_Customer__c> next()
{
Integer temp = 0;
if(getlbtc.size()>10)
{
if(i < getlbtc.size())
{
g.clear();
i = i+10;
for(j=j+10;j<i;j++)
if(j < getlbtc.size())
{
g.add(getlbtc[j]);
temp++;
}
else
break;
j = j-10;
}
getGetlbtc();
}
else
g = getlbtc;
if((temp!=10)&&(flag==0))
{
j = j-temp+10;
flag = 1;
system.debug('temp j:'+j);
}
return null;
}
public PageReference prev()
{
if(getlbtc.size()>10)
{
if(j>0)
{
g.clear();
for(k=j-1;K>j-11;K--)
if(k>=0)
g.add(getlbtc[k]);
else
break;
i = j;
j = j-10;
}
List<Bill_To_Customer__c> g1 = new List<Bill_To_Customer__c>();
Integer x=0,y=9;
g1 = g.deepclone();
for(x=0;x<10;x++){
g.set(y,g1.get(x));
y--;
}
getGetlbtc();
}
else
g = getlbtc;
return null;
}
public List<Bill_To_Customer__c> getGetlbtc() {
return g;
}
}
Updated code for pagination http://wiki.apexdevnet.com/index.php/Pagination
http://wiki.apexdevnet.com/index.php/Pagination
so something that's very basic in just about any modern programming language is members-only content here?
am I missing something?