Jump to content
pipo_

HelperList and pagination

Recommended Posts

hi,

 

i am build new module for administration, but i have problem with helperList (http://doc.prestashop.com/display/PS15/HelperList)

 

i can load products to list, but pagination is not working, also helperList returns 0 in total results

$helperList = new HelperList();
		 
$helperList->bulk_actions = array(
	'delete'=>array(
	   'text'=>$this->l('Delete selected'), 
	    'confirm'=>$this->l('Delete selected items?'))
	);
		
$helperList->_select = Product::getProducts($this->context->language->id, 0, '','id_product','ASC');
	
$helperList->_defaultOrderBy = 'id_product';
        
$fields_list = array(
	'id_product' => array(
		'title' => $this->l('ID'),
		'align' => 'center',
		'width' => 50,
	),
	'name' => array(
		'title' => $this->l('Name'),
		'width' => 'auto'
	)
);
		
$helperList->identifier = 'id_product';
$helperList->title = $this->l('Produkty a kategórie');
$helperList->token = Tools::getAdminTokenLite('AdminModules');
$helperList->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
		
$helperList->table = $this->name.'_products';
		
	  
return $helperList->generateList($helperList->_select, $fields_list);  

post-369621-0-11512500-1390837956_thumb.jpg

  • Like 1

Share this post


Link to post
Share on other sites

Why you are use $helperList->_select to define your data list ?

There is no protected variable $_select within Helper object

 

Total numbers of data results, should be defined using $listTotal variable in your helper object.
If listTotal is undefined, then it will use 0 as defaut value and then your pagination won't work because the total page = 1

Pagination also won't work if the total number of data less than pagination value

$fields_list['id_whatever'] = array(
            'title' => $this->l('ID'),
            'align' => 'center',
            'type' => 'int',
            'width' => 40
        );
$fields_list['name'] = array(
            'title' => $this->l('Name'),
            'filter_key' => 'b!name'
        );

$result = // your query here, 2 dimensional array(), e.g array(array('id_whatever' => 1, 'name' => 'whatever'))

$helper = new HelperList();
$helper->listTotal(count($result)); // define the total numbers of result to be displayed

// rest of helper vars

return $helper->generateList($result, $fields_list);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More