Jump to content

2 tables in the same page


A Zayed
 Share

Go to solution Solved by DawPi,

Recommended Posts

I'm trying to show 2 tables in the same page, everything goes fine except for the pagination part, table reloads without changing contents...

Even I use different paginationKey and different sortKey for both tables, but pagination is broken, is it a bug? or am I missing something?

Code:

	/* First Table */
	$table_1 = new \IPS\Helpers\Table\Db('first_table', \IPS\Request::i()->url(), array() );
	$table_1->include = array( 'col1', 'col2', 'col3');
	$table_1->mainColumn = 'col1';
	$table_1->parsers = array(
		'col2' => function ($val, $row) {
			return \IPS\DateTime::ts($val);
		}
	);
	$table_1->sortBy = $table_1->sortBy ?: 'col2';
	$table_1->sortDirection = $table_1->sortDirection ?: 'desc';
	$table_1->limit = 5;
	$table_1->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core', 'admin' ), 'rows' );
	$table_1->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core', 'admin' ), 'table' );	
	$table_1->paginationKey = 'firstTablePage';
	$table_1->resortKey = 'firstTableResort';
	
	/* Second Table */			
	$table_2 = new \IPS\Helpers\Table\Db('second_table',  \IPS\Request::i()->url(), array() );
	$table_2->include = array( 'col1', 'col2', 'col3');
	$table_2->mainColumn = 'col1';
	$table_2->parsers = array(
		'col2' => function ($val, $row) {
			return \IPS\DateTime::ts($val);
		}
	);
	$table_2->sortBy = $table_2->sortBy ?: 'col2';
	$table_2->sortDirection = $table_2->sortDirection ? : 'desc';
	$table_2->limit = 5;
	$table_2->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core', 'admin' ), 'rows' );
	$table_2->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'tables', 'core', 'admin' ), 'table' );	
	$table_2->paginationKey = 'secondTablePage';
	$table_2->resortKey = 'secondTableResort';
	
	return \IPS\Theme::i()->getTemplate( 'tempGroup', 'temp' )->browse( (string) $table_1, (string) $table_2 );	

 

Link to comment
Share on other sites

Does your table template has the params? I had this issue yesterday. 

It was:

<div data-role="tablePagination"> {template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit"} </div>



 

When should be:

<div data-role="tablePagination"> {template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit, TRUE, $table->getPaginationKey()"} </div>

And:

<div data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}' data-controller='core.global.core.table{{if $table->canModerate()}},core.front.core.moderation{{endif}}'>


 

when should be:

<div data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}' data-controller='core.global.core.table' {{if $table->getPaginationKey() != 'page'}}data-pageParam='{$table->getPaginationKey()}'{{endif}}>

Link to comment
Share on other sites

7 minutes ago, Adriano Faria said:

Does your table template has the params? I had this issue yesterday. 

It was:

 


<div data-role="tablePagination"> {template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit"} </div>



 

I'm using the core admin tables:

		<div data-role="tablePagination" class='ipsSpacer_bottom'>
			{template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit"}
		</div>

 

Link to comment
Share on other sites

7 minutes ago, DawPi said:

system/Helpers/Table/Table.php


	/**
	 * @brief	Pagination parameter
	 */
	protected $paginationKey	= 'page';

 

 look up GIF by Dumbfoundead

This;)

 

 

You could also use unique urls, that's what I was using all the time. The issue is that you can't use the same url for both tables. ( I guess that's probably even the better solution, but the other should also work)

	$table_1 = new \IPS\Helpers\Table\Db('first_table', \IPS\Request::i()->url(), array() );

 

 

Link to comment
Share on other sites

@A Zayed is properly using different paginationKey and resortKey in both tables so I'm not sure why indicate it here; it's in his first post. The issue here was the core template, which hasn't the latest 2 parameters in pagination template and also missing the data-pageParam in the table div.

22 minutes ago, Daniel F said:

The issue is that you can't use the same url for both tables.

Yes, you can. I use it here and on a plugin developed yesterday, where I noticed the missing stuff in templates:

		/* Featured Images */
		$featured 			= new \IPS\gallery\Image\Table( 'IPS\gallery\Image', \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse', 'front', 'gallery' ), array( array( 'image_feature_flag=?', 1 ) ) );
		$newest 			= new \IPS\gallery\Image\Table( 'IPS\gallery\Image', \IPS\Http\Url::internal( 'app=gallery&module=gallery&controller=browse', 'front', 'gallery' ) );

 

All comes down to the paginationKey and resortKey.

Link to comment
Share on other sites

  • 2 years later...
On 12/17/2019 at 5:51 PM, Adriano Faria said:

Does your table template has the params? I had this issue yesterday. 

It was:

 

<div data-role="tablePagination"> {template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit"} </div>



 

When should be:

 

<div data-role="tablePagination"> {template="pagination" group="global" app="core" location="global" params="$table->baseUrl, $table->pages, $table->page, $table->limit, TRUE, $table->getPaginationKey()"} </div>

 

And:

 

<div data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}' data-controller='core.global.core.table{{if $table->canModerate()}},core.front.core.moderation{{endif}}'>


 

when should be:

 

<div data-baseurl='{$table->baseUrl}' data-resort='{$table->resortKey}' data-controller='core.global.core.table' {{if $table->getPaginationKey() != 'page'}}data-pageParam='{$table->getPaginationKey()}'{{endif}}>

 

Hello,

Could you please consider to add the above to the core / admin / table template so I can use pagination (paginationKey) in my tables? In this case I have two tables and pagination doesn't work:

cpWKp4M.png

Reason: to make pagination work now, I have to copy the entire template and add $table->getPaginationKey() it on it to pagination works.

Thank you.

Edited by Adriano Faria
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...