⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Clear the search on revisit



Amit Shah
  • profile picture
  • Member

Posted 05 February 2014 - 11:22 AM

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


DrPaul
  • profile picture
  • Member

Posted 27 February 2014 - 19:43 PM

Looks great, but delete_cookie() is coming up as undefined.

 

[Edit]

 

Ah, I see - you need to include $this->load->helper('cookie');

 

Many thanks!!!

 

This was one aspect of GC that was driving me mad :-)


Amit Shah
  • profile picture
  • Member

Posted 28 February 2014 - 07:35 AM

Welll if something drives u mad.. lead to a solution and share it :) ..

Happy GCing:)


DrPaul
  • profile picture
  • Member

Posted 17 June 2014 - 17:17 PM

BTW in clearSearchCookies() shouldn't you be passing in the URL as an argument?

 

Your code has "manage/retailers" hard-wired in the function definition.


Amit Shah
  • profile picture
  • Member

Posted 18 June 2014 - 08:26 AM

yes my mistake.. i agree.  ihave had the code functioned for my work and then just copy pasted so some1 can use the trend / pattern 2 resolve the issue :)


DrPaul
  • profile picture
  • Member

Posted 18 June 2014 - 17:03 PM

yes my mistake.. i agree.  ihave had the code functioned for my work and then just copy pasted so some1 can use the trend / pattern 2 resolve the issue :)

Certainly helped me out! (and it's easy to see how to pass the value into the function)

 

Thanks once again.


kanted
  • profile picture
  • Member

Posted 04 December 2015 - 05:06 AM

please can you share the final corrected code and tell me where to put that. great thanks.I am not a programmer but have made gc work and need this feature. it would be super nice if I can make it work. 

in love with grocery crud.


batara_k
  • profile picture
  • Member

Posted 26 May 2016 - 01:29 AM

can you share the final code and how to use it ??