Adding custom action button in PrestaShop renderlist – We can easily use ‘view’, ‘edit’, ‘delete’ buttons in Prestashop render list by the help of addRowAction(‘view’) function. But what if we need to add some custom buttons in the list!! we can use PrestaShop field list ‘callback’ property for the same.
Add a temp array key in you $this->fields_list array :
$this->fields_list = array(
'id_temp' => array(
'title' => $this->l('My Button'),
'align' =>'text-right',
'search' => false,
'callback' => 'viewMyButton',
),
}
id_temp is an alias of your list id, you can define this like :
$this->_select = 'a.`id` as `id_temp`';
Now create a function with callback name viewMyButton
public function viewMyButton($id)
{
return '<span class="btn-group-action">
<span class="btn-group">
<a class="btn btn-default" href="'.self::$currentIndex.'&token='.$this->token.'&view'.$this->table.'&id='.$id.'"><i class="icon-search-plus"></i> '.$this->l('View').'
</a>
</span>
</span>';
}
This will create a button in the render list like this :
If you want to display multiple buttons, you need to write the HTML for that only,
public function viewMyButton($id)
{
return '<span class="btn-group-action">
<span class="btn-group pull-right">
<a class="btn btn-default" href="'.self::$currentIndex.'&token='.$this->token.'&view'.$this->table.'&id='.$id.'"><i class="icon-search-plus"></i> '.$this->l('My Button1').'
</a>
<button data-toggle="dropdown" class="btn btn-default dropdown-toggle">
<i class="icon-caret-down"></i>
</button>
<ul class="dropdown-menu">
<li>
<a class="delete" title="Delete" href="#">
<i class="icon-trash"></i> My Button2
</a>
</li>
</ul>
</span>
</span>';
}
This will look like this :
Thanks.


Be the first to comment.