Yes indeed I did find a solution but didn't have time to post about it. They key here is the following two lines:
$this->_defaultOrderBy = 'a.some_date';
$this->_defaultOrderWay = 'ASC';
So in addition to all of the things I have mentioned in the example, we also need to fetch the values for these fields from the query string. In my case the query string parameter looks like [tablename]Orderby=
i.e. in above example it will be custom_tableOrderby=
To fetch the value from query string do the following in the construct
function:
$sortBy = Tools::getValue('custom_tableOrderby');
$sortWay = Tools::getValue('custom_tableOrderway', 'ASC'); // default sortWay is Ascending
$this->_defaultOrderWay = $sortWay;
if ($sortBy == 'field_name_in_your_view') {
$this->_defaultOrderBy = 'field_name_in_table';
} else if ($sortBy == 'another_field_name_in_your_view') {
$this->_defaultOrderBy = 'another_field_name_in_table';
I hope it works for you as I implemented this in Prestashop 1.5 a very long time ago.