I am working on a back office module controller. I am able to display my object in a list view and also create a new one using the helper form. However, the default list view that I have, does not sort or filter anything. The list view shows the controls for sorting and filtering but clicking on them does nothing. Here is my back office controllers:
class AdminCustomController extends AdminController {
public $module;
public function __construct() {
$this->table = 'custom_table';
$this->className = 'CustomTable';
$this->module = 'customtable';
$this->lang = false;
$this->bootstrap = true;
$this->need_instance = 0;
// Building the list of records stored within the "test" table
$this->fields_list = array(
'id_custom_table' => array(
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25,
'type' => 'text'
),
'name' => array(
'title' => $this->l('Name'),
'width' => 'auto',
'type' => 'text',
'orderby' => true,
'search' => true
//the ordering and filtering controls do appear but they don't work
),//...some more fields
);
$this->_select = '....';
$this->_join = '
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` b ON (b.`id_product` = a.`id_product`)';
$this->_defaultOrderBy = 'a.some_date';
$this->_defaultOrderWay = 'ASC';
$this->context = Context::getContext();
parent::__construct();
}
public function renderForm() {
// Building the Add/Edit form
$this->fields_form = array(
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
$this->addJqueryUI(array('ui.datepicker', 'ui.autocomplete'));
return parent::renderForm();
}
public function renderList() {
return parent::renderList();
}
}
I have looked at code of other modules and also default PS controllers and all of them just return the parents list view unless it is modified and by default the sorting and filtering feature works fine on them. I did not see any sorting or filtering specific code and that is why my admin controller does not have any.
I would appreciate if you can help me understand and enable the sorting and filtering in my back office list view. I feel that I have missed something but I can't figure out what?
In prestashop 1.6 (I think it has to be the same in PS 1.5) :
The easiest way I found to get the sorting and filtering working in custom ModuleAdminController is to init the parent of postProcess() if it is overrided :
public function postProcess() {
parent::postProcess();
...
}
And the sorting/filtering works just like it has to without any custom code.
Enjoy. = )