I have followed the article on the Joomla Developer Sites to create a sorting filter for my list (https://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component).
But I cannot get it work. Step 2 explains how to get the State of the sorting. But the state is NULL after calling get GetState-Method. Here is the Method I have used.
$state = $this->get('State');
Best regards tria1312
Add a comment |
1 Answer
The meaning of $state = $this->get('State'); is $state = $model->getState(); where $model is the current model of your view.
If your model is extending from JModelList, all your state variables are automatically populated (provided correct values present in request). Otherwise populate the state in your model's populateState function.
protected function populateState ($ordering = 'sort_order', $direction = 'ASC') { $orderCol = $app->input->get('filter_order', $ordering); $this->setState('list.ordering', $orderCol); } Note: Never call getState function in populateState, which creates infinite loop.
- Does it also work with the JModelLegacy Class?tria1312– tria13122016-08-22 19:43:15 +00:00Commented Aug 22, 2016 at 19:43
- Yes. you can add your own populateState method in your model and populate the values from request manually.Nagarjun– Nagarjun2016-08-22 20:10:11 +00:00Commented Aug 22, 2016 at 20:10
- OK, thats working. And now I want to have the state populated when a request with special task is called. How does this work? In that case my list.ordering is always empty.tria1312– tria13122016-08-22 21:27:40 +00:00Commented Aug 22, 2016 at 21:27
- I found it. You have to fetch the State by calling the Method $app->getUserState( 'list.column', 'default_column_name' );tria1312– tria13122016-08-22 22:02:58 +00:00Commented Aug 22, 2016 at 22:02