Jump to content


Clear the search on revisit

search revisit clear search

  • Please log in to reply
7 replies to this topic

#1 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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



#2 DrPaul

DrPaul

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 27 February 2014 - 07: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 :-)



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 28 February 2014 - 07:35 AM

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

Happy GCing:)



#4 DrPaul

DrPaul

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 17 June 2014 - 05: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.



#5 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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 :)



#6 DrPaul

DrPaul

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 18 June 2014 - 05: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.



#7 kanted

kanted

    Member

  • Members
  • PipPip
  • 19 posts

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.



#8 batara_k

batara_k

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 26 May 2016 - 01:29 AM

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







Also tagged with one or more of these keywords: search, revisit, clear search

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users