Well i was in much annoying situation when i had client repetitively asking for a scenario - In flexigrid - when he searches for a certain content - fine he gets filtered result. Then uses the navigation menu to go to some other page and then when he again calls back to that page (where he filtered the data earlier) - he has to go to the bottom / clear the filtering and then only he was able to proceed. This was more annoying - Hence here is what i provided the solution for the same. Wherever in the controllers u need to incorporate it - just make a call to clearSearchCookies - It wont clear away the cookies right away - it will clear only if the refering url is not found to be containing the same then it will delete the cookies - wipe off the filter cookies set by flexigrid to maintain the intelligence of the component.
Following functions are added in the helper class that can be automatically be loaded or can be loaded on demand - And this is to be called up in each controller's method - if required to clear the search cookies on revisit.
if ( ! function_exists('clearSearchCookies')) { function clearSearchCookies() { //Check if the referer is not same as this page then clear the cookies $thisurl = site_url() . "manage/retailers"; if(array_key_exists('HTTP_REFERER', $_SERVER)) { $refering_url = $_SERVER['HTTP_REFERER']; if($refering_url != '') { if(substr($refering_url, 0, strlen($thisurl)) == $thisurl) { //Fine to go with .. since it is the same one continued in here } else { deleteSearchCookies(); } } else { deleteSearchCookies(); } } else { deleteSearchCookies(); } } } if ( ! function_exists('deleteSearchCookies')) { function deleteSearchCookies() { foreach ($_COOKIE as $key=>$val) { if(stripos($key, 'crud_page') !== FALSE) { delete_cookie($key); } if(stripos($key, 'per_page') !== FALSE) { delete_cookie($key); } if(stripos($key, 'hidden_ordering') !== FALSE) { delete_cookie($key); } if(stripos($key, 'search_text') !== FALSE) { delete_cookie($key); } if(stripos($key, 'search_field') !== FALSE) { delete_cookie($key); } } } }
Happy GCing