0

Here is my code of .tpl file:

<div class="view-content">
<h3>...</h3>
{include file="CRM/common/pager.tpl" location="top"}
{strip}
    <table class="display">
        <thead>
        <tr>
            ...
        </tr>
        </thead>
        <tbody>

        {foreach from=$rows item=row}
            ...
        {/foreach}
        </tbody>
    </table>
{/strip}
{include file="CRM/common/pager.tpl" location="bottom"}
</div>
{include file="CRM/common/jsortable.tpl"}

and Code for setting up Pager:

/**
 * Setting up $_pager for pagination support
 * Used CRM_Utils_Pager & CRM/common/pager.tpl to handle pagination
 */
public function pager() {
    // Setting up parameters for Pager that we are gonna create
    $params['status'] = ts('Some Entity %%StatusMessage%%');
    $params['csvString'] = NULL;
    $params['buttonTop'] = 'PagerTopButton';
    $params['buttonBottom'] = 'PagerBottomButton';
    $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
    if (!$params['rowCount']) {
        $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
    }

    // Getting all Some Entity by Contact ID. if $_contactId is null then it return value for all Contact.
    $params['total'] = civicrm_api3( 'Entity', 'getcount', array( 'contact_id' => $this->_contactId ) );;

    // Setup Pager object and assign into template so it can be used by CRM/common/pager.tpl
    $this->_pager = new CRM_Utils_Pager($params);
    $this->assign_by_ref('pager', $this->_pager);
}

Thanks.

1

I have found the Problem, Problem was inside pager.tpl

pager.tpl generate some js to handle ajax page loading When pager.tpl location variable != top

That's js look like this without compiled(in pager.tpl):

{if $location neq 'top'}
  <script type="text/javascript">
    {literal}
    CRM.$(function($) {
      {/literal}
      var
        $form = $({if empty($form.formClass)}'#crm-main-content-wrapper'{else}'form.{$form.formClass}'{/if}),
        numPages = {$pager->_response.numPages},
        currentPage = {$pager->_response.currentPage},
        perPageCount = {$pager->_perPage},
        currentLocation = {$pager->_response.currentLocation|json_encode},
        spinning = null,
        refreshing = false;
      {literal}
      function refresh(url) {
        if (!refreshing) {
          refreshing = true;
          var options = url ? {url: url} : {};
          $form.off('.crm-pager').closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh');
        }
      }

      ...

      $form
        .on('click.crm-pager', 'a.ui-spinner-button', function(e) {
          var $el = $(this);
          // Update after a short delay to allow multiple clicks
          spinning !== null && window.clearTimeout(spinning);
          spinning = window.setTimeout(function() {
            if ($el.is('.crm-pager a')) {
              page($el.siblings('input[name^=crmPID]').spinner('value'));
            } else {
              changeCount($el.siblings('input.crm-rows-per-page-select').spinner('value'));
            }
          }, 200);
        })
        // Handle sorting, paging and alpha filtering links
        .on('click.crm-pager', 'a.crm-pager-link, #alpha-filter a, th a.sorting, th a.sorting_desc, th a.sorting_asc', function(e) {
          refresh($(this).attr('href'));
          e.preventDefault();
        });
    });
    {/literal}
  </script>

#crm-main-content-wrapper is the main container of All tabs link and tab content. that's why it's html/content replaced by ajax response html.

To fix this what I have done:

Here is my .tpl file code(after fixed):

<form class="Your_Unique_Class_Name">
<div class="view-content">
  <h3>...</h3>
  {include file="CRM/common/pager.tpl" location="top"}
  {strip}
   <table class="display">
    <thead>
    <tr>
        ...
    </tr>
    </thead>
    <tbody>

    {foreach from=$rows item=row}
        ...
    {/foreach}
    </tbody>
    </table>
    {/strip}
    {include file="CRM/common/pager.tpl" location="bottom"}
</div>
{include file="CRM/common/jsortable.tpl"}
</form>

and Code for setting up Pager:

/**
 * Setting up $_pager for pagination support
 * Used CRM_Utils_Pager & CRM/common/pager.tpl to handle pagination
 */
public function pager() {


    $this->assign( 'form', array( 'formClass' => 'Your_Unique_Class_Name' ) );


    // Setting up parameters for Pager that we are gonna create
    $params['status'] = ts('Some Entity %%StatusMessage%%');
    $params['csvString'] = NULL;
    $params['buttonTop'] = 'PagerTopButton';
    $params['buttonBottom'] = 'PagerBottomButton';
    $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT);
    if (!$params['rowCount']) {
        $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT;
    }

    // Getting all Some Entity by Contact ID. if $_contactId is null then it return value for all Contact.
    $params['total'] = civicrm_api3( 'Entity', 'getcount', array( 'contact_id' => $this->_contactId ) );;

    // Setup Pager object and assign into template so it can be used by CRM/common/pager.tpl
    $this->_pager = new CRM_Utils_Pager($params);
    $this->assign_by_ref('pager', $this->_pager);
}

It's taken me long hours to find out this problem solution;

I think it will help you so that's why sharing with you!

Thanks

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.