📣 We're Hiring!

Add Page Numbers to ListViews

I have worked on adding page numbers to the bottom of all list view pages. Instead of clicking next, next, next all the time, I added page numbers. I know you can filter but, sometimes just an old-fashioned button that takes you to the page is the way to go. Currently, there is no way to indicate which page you are on. Perhaps someone else can continue on with this.

File: include/ListView/ListViewData.php

Starting on Line 560 add:

$listModule = $seed->module_dir;
$moduleUpper = strtoupper($seed->module_dir);
$moduleString = $listModule . 2 . "_" . $moduleUpper . "_offset";
$pgButtons[] = "";
$numberOfLoops =  (int) ($totalCount / $this->getLimit()) ;

for ($i=0; $i <= $numberOfLoops ; $i++) { 
        $pgOffSet = $i * $this->getLimit();  
        $pg = $i + 1;
        array_push($pgButtons, "<button type='button' id='page_$i' name='listViewStartButton' class='list-view-pagination-button' onClick='return sListView.save_checks($pgOffSet, \"$moduleString\")'> $pg</button>");

}

    $pageData['pgNums'] = $pgButtons;
    $queryString = '';

File themes/SuitP/include/ListView/ListViewPaginationBottom.tpl
Starting on Line 114

<tr><td>
     <strong>Page:</strong> 
     {foreach from=$pageData.pgNums item=button}
              {$button}
     {/foreach}
</td></tr>

Haven’t tested but looks interesting.
BTW, If you don’t mind, this post is worth of the Show and Tell Category. Please let me now if you authorize us to move it.

I actually changed this to a dropdown.


Originally I had buttons but this might get out of hand. So I changed it to a dropdown. I also added the ability to show what page you are on. This isn’t perfect, but perhaps someone can make it better. This is very similar to my original modification. Here is my code.

File: include/ListView/ListViewData.php

Starting on Line 560 add:

    $listModule = $seed->module_dir;
    $moduleUpper = strtoupper($seed->module_dir);
    $moduleString = $listModule . 2 . "_" . $moduleUpper . "_offset";

    $pgButtons[] = "";
    $pageLimit = $this->getLimit();
    $numberOfLoops =  (int) ($totalCount / $pageLimit) ;

    $pageData['perPage'] = $this->getLimit();
    $pageData['pgNums'] = $pgButtons;

    $pgDropdown[] = "";
    for ($a=0; $a <= $numberOfLoops ; $a++) { 
        $pgOffSet = $a * $this->getLimit();  
        $pga = $a + 1;
        array_push($pgDropdown, "<option value='$pgOffSet,$moduleString'>$pga</option>");
    }
    $pageData['pgNumsDrop'] = $pgDropdown;

File themes/SuitP/include/ListView/ListViewPaginationBottom.tpl
Starting on Line 43:

 <script language="JavaScript" type="text/javascript">
    {literal}
   window.onload = function() {

 var last = {/literal}{$pageData.offsets.lastOffsetOnPage}{literal};
 var perPage = {/literal}{$pageData.perPage}{literal};
 var page = Math.floor (last /perPage) - 1;
 
 document.getElementById('pgdropTop').selectedIndex = page;
 document.getElementById('pgdropBottom').selectedIndex = page;

};

function leaveChangeBottom(){

  pageString = document.getElementById('pgdropBottom').value;
  var pgArray = pageString.split(",");

   sListView.save_checks(parseInt(pgArray[0]),pgArray[1]);
}
 {/literal}
</script>

Then again on line 96:

<select id="pgdropBottom" onchange="leaveChangeBottom()">
		{foreach from=$pageData.pgNumsDrop item=optionDrop}
						{$optionDrop}
		{/foreach}

File themes/SuitP/include/ListView/ListViewPaginationTop.tpl
Starting on Line 43:

 <script language="JavaScript" type="text/javascript">
 {literal}
 window.onload = function() {
     var last = {/literal}{$pageData.offsets.lastOffsetOnPage}{literal};
     var perPage = {/literal}{$pageData.perPage}{literal};
     var page = Math.floor (last /perPage) - 1;
     document.getElementById('pgdropTop').selectedIndex = page;
     document.getElementById('pgdropBottom').selectedIndex = page;
};

 function leaveChangeTop(){
  	pageString = document.getElementById('pgdropTop').value;
    var pgArray = pageString.split(",");
   sListView.save_checks(parseInt(pgArray[0]),pgArray[1]);
}
{/literal}
</script>

Then Line 94:

	<select id="pgdropTop" onchange="leaveChangeTop()">
		{foreach from=$pageData.pgNumsDrop item=optionDrop}
				{$optionDrop}
		{/foreach}
     </select>

If you have custom modules the above will work. Custom modules do not add an ‘s’ at the end. Whereas Accounts turns ACCOUNTS and it needs to be ACCOUNT. If you are not using custom modules then you need to add this in ListViewData.php. I turned this into an IF statement. (If not custom module then don’t do)

It would go in ListViewData.php underneath the line: $moduleUpper = strtoupper($seed->module_dir);

$moduleUpper = substr($moduleUpper, 0, -1);

Mine looks like this:

  $listModule = $seed->module_dir;
  $moduleUpper = strtoupper($seed->module_dir);

    if ($moduleUpper == "CST_MODULE1" || $moduleUpper == "CST_MODULE2"){
    }else{
        $moduleUpper = substr($moduleUpper, 0, -1); 
    }
1 Like

Post it where ever you like. I am sure it isn’t perfect. Perhaps people could improve upon it.

Will move it. Thanks for sharing your work. I’m sure many will find it usefull.