Buy Now
Sign in

Keep search term in the search widget field when moving from page to page with paginator

simelas , August 22 at 16:49
Answered
S
simelas
Hello everyone, hello Max
Question came few times : is there a simple way to keep the search term in the search field of the search widget, while moving from page to page with the paginator.
(This show an example of the solution i applied for Chronoconnectivity6 with the search widget but can be applied to any selector /filter.
Explanation: Currently (01 September2018) when filtering a database with the "Search Widget" , having set Model.field:{data:keywords}/- in the WHERE conditions of the database read function, the behaviour is as expected. e.g. the filter works properly.
However when moving from one page to the other using the paginator, the value in the search field is erased at the first move.
Debug show that on initial run: e.g. on using the search button, the keywords field if correctly filled. ( As example here i used [keywords] =>fire ; having on purpose worked with "Build a Basic lisitng" ).
Array​
​(​
​ [option] => com_chronoconnectivity6​
​ [cont] => manager​
​ [conn] => article​
​ [event] => index​
​ [text5] => ​
​ [keywords] => fire
Then when clicking on one of the paginator page , the filter is reset to blank,more precisely the additonnal parameter ( in the present case [keywords] => fire ) is not included in the paginator url of the paginator
Array​
​(​
​ [option] => com_chronoconnectivity6​
​ [cont] => manager​
​ [conn] => article​
​ [event] => index​
​ [startat] => 0
(If after having filtered, one add manually a parameter to the paginator ( &keywords=fire) then the paginator works as expected : e.g. one can navigate through the paginated views with the paginatorkeeping the filtered data. Conclusion: the search parameter is not properly passed to the paginator (or this is not the right method)).
Solution applied:
In the relevant Form of the Views tab add an event that you can call 'select' for exemple.
In the Functions tab add a redirect action named for example "redirect_select' and for that redirect action add: in "Event" add index ; in "Redirect URL" add {url_self} ; in "URL Parameters" add the parameters of the desired filter field(s) , for example keywords={data:keywords} state={data:state} country_id_select={data:country_id_select} .
In Events tab add a new event named 'select'. In this event add {fn:redirect_select} and {redirect:index}
Save your connection and test. Now the paginator should behave as expected when using filters.
Several post in the forum ask for a solution and some solutions seems to have been proposed but nothing definitively crystal clear. Maybe there is a simpler way than the one proposed but at least it works well.
Maybe Max could you work a little bit on that matter.
Best Regards,
simelas