Jump to content

\IPS\Helpers\Table\Custom pagination issue


newbie LAC

Recommended Posts

Hello,

		$data = array();
		
		foreach (range(1,100) as $r)
		{
			$data[] = array(
				'field1' => 'value' . $r
			);
		}

		$table = new \IPS\Helpers\Table\Custom(
			$data,
			\IPS\Http\Url::internal("app=app&module=module&controller=controller")
		);
		
		$table->quickSearch = 'field1';

		\IPS\Output::i()->output = (string) $table;

pagination.thumb.jpg.257988c3126802c70209d48c823c39f9.jpg

Search by value11

pagination2.thumb.jpg.6945fe8023caff18580b58c9af3ca7cd.jpg

pagination3.thumb.jpg.b5bc104c7847c0736126084d59d8aa25.jpg

This is also affect on built in functions

E.g. SQL toolbox

sql.thumb.jpg.7979ea9ca1cbe5f148698654664f5395.jpg

sql2.thumb.jpg.870006c8d67c8218e8fee5c1ea057c1b.jpg

Link to comment
Share on other sites

  • 2 months later...

Hello,

On 7/29/2019 at 10:18 PM, bfarber said:

Thanks, I've added an internal bug report to get this checked into.

Your fix broke some my custom tables. I don't use quick search and pass to $dataSource X items returned for current page

Could you change this?

For example move

        $this->count = \count( $rows );
        $this->pages = ceil( $this->count / $this->limit );

inside 

        if ( $this->quickSearch !== NULL and \IPS\Request::i()->quicksearch )
        {
            $quickSearchColumn = $this->quickSearch;
            $rows = array_filter( $rows, \is_callable( $this->quickSearch ) ? $this->quickSearch : function( $row ) use ( $quickSearchColumn )
            {
                return mb_strpos( mb_strtolower( $row[ $quickSearchColumn ] ), mb_strtolower( trim( \IPS\Request::i()->quicksearch ) ) ) !== FALSE;
            } );

            // HERE
        }

Thanks

Link to comment
Share on other sites

12 hours ago, bfarber said:

Can you please clarify how I can see this (new) concern in action? When I use the SQL toolbox as an example, pagination seems to work normally.

 

20 hours ago, newbie LAC said:

Your fix broke some my custom tables.


I found bug during development application

Since you don't like custom code I ofund example (sql toolbox) in the Suite

For this I couldn't find code in the Suite

Link to comment
Share on other sites

15 hours ago, bfarber said:

Ok if you're not seeing an example in the Suite, can you at least outline/clarify what the new issue is that is occurring? Why does moving those lines up as you suggest resolve the problem? We may be able to test a quick contrived example that way.

Example

I use some API

https://domain.tld/api/?k=val&limit=25

The limit is from 10 to 25. Default is 10

Output is

total: 250

results: list of items

I can't get more than 25 items. But I can use offset

https://domain.tld/api/?k=val&limit=25&offset=25

The table 

$limit = 25;
$page = (isset(\IPS\Request::i()->page) and (\intval(\IPS\Request::i()->page) > 0)) ? \IPS\Request::i()->page : 1;
$offset = ($limit * ($page - 1));

$data = array(
	'results' => array(),
	'total' => 0,
);

try
{
	$data = \IPS\Http\Url::external('https://domain.tld/api')
		->setQueryString(
			array(
				'k' => 'val',
				'limit' => 25,
				'offset' => $offset,
			)
		)
		->request()
		->get()
		->decodeJson();
}
catch (\Exception $e) {}

$table = new \IPS\Helpers\Table\Custom($data['results'], $url);

$table->limit = $limit;
$table->pages = ceil($data['total'] / $limit);

250/25 = 10 pages

With your fix

		$this->count = \count( $rows );
		$this->pages = ceil( $this->count / $this->limit );

$this->count = \count( $rows ); // 25 (I pass 25 items)

$this->pages = ceil(25 / 25 ); // 1 page


Since I don't use quick search move the code inside condition resolve my issue

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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