Back to Top

Adding custom action button in PrestaShop renderlist

Updated 13 October 2016

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 :

Searching for an experienced
Prestashop Company ?
Find out More
$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>&nbsp;'.$this->l('View').'
                    </a>
                </span>
            </span>';
}

 

This will create a button in the render list like this :

single action button

 

 

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>&nbsp;'.$this->l('My Button1').'
                        </a>
                        <button data-toggle="dropdown" class="btn btn-default dropdown-toggle">
                        <i class="icon-caret-down"></i>&nbsp;
                    </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 :

multiple action button

 

Thanks.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home