Global Search

QuestionsGlobal Search
Gabriel Robles asked 7 years ago

Dear,

I bought the product last week to implement on my website. Everything works OK but I need a functionality to simplify the search of my clients in the table.

I need a GLOBAL SEARCHING functionallity, like a text box where you can write your search and it filters by any value in any column.

There is an axample from PHPGRID.COM: https://phpgrid.com/example/multiple-fields-global-search/

Is it this possible to have this functionality in this product?

Thanks.

Gabriel.

8 Answers
Abu Ghufran answered 7 years ago

Yes this is doable. You can refer code of demos/search/search-form.php demo.
It allow external form to do search on your desired fields.

Gabriel Brezuica answered 7 years ago

Thanks Abu!
Just another small thing. Could you please let me know how to "Autofilter"? I'd like the filter applies once I write down without touching "Filter" Button.

Thanks

Abu Ghufran answered 7 years ago

Instead of
jQuery("#search_text").click(…)

You can change it to
jQuery("#filter").keydown(…)

I've not tested it but it's plain JS/Jquery code.

Gabriel Brezuica answered 7 years ago

Dear Abu,

I have two more question realted to the above.

1) How do I make the search case-insensitive?

For example:

I have a column "Description" with a register like "Hand Blender"…
When I look for "hand blender" or "HAND BLENDER" there are no results. But yes when I look for "Hand"or "Hard Blender".

I'm using the demo: "demos/search/search-form.phps" and I'm loading the data from an array. I'm also using the Full Version of the Framework. When I use your demo, the search is case insensitive, but not when I use it in my case. I think that it is because i'm loading from array and your not.

The jQuery code for the filter is:
******************************************************************************
jQuery("#search_text").click(function() {
grid = jQuery("#list1");

// open initially hidden grid
// $('.ui-jqgrid-titlebar-close').click();

var searchFiler = jQuery("#filter").val(), f;

if (searchFiler.length === 0) {
grid[0].p.search = false;
jQuery.extend(grid[0].p.postData,{filters:""});
}
f = {groupOp:"OR",rules:[]};

// initialize search, 'name' field equal to (eq) 'Client 1'
// operators: ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
// equal, not equal,

f.rules.push({field:"certificate",op:"bw",data:searchFiler});
f.rules.push({field:"mark",op:"bw",data:searchFiler});
f.rules.push({field:"description",op:"bw",data:searchFiler});
f.rules.push({field:"origin",op:"bw",data:searchFiler});
f.rules.push({field:"products",op:"bw",data:searchFiler});
f.rules.push({field:"OT",op:"bw",data:searchFiler});

grid[0].p.search = true;
jQuery.extend(grid[0].p.postData,{filters:JSON.stringify(f)});

grid.trigger("reloadGrid",[{jqgrid_page:1,current:true}]);

return false;
});
******************************************************************************

2) How do I make the search be anywhere in the String and not from the beginning?

For example:

In the column "Products" I have a register like "KA-CM700, KA-CM600, KC-CT250, KR-CM100". When a search, for example, "KC-CT250", there are no results. I realized that the search is from the beginning of the String.

Please, can you help me with this?

Thanks a lot!

Gabriel.

Abu Ghufran answered 7 years ago

Hello,

1) Perhaps due to mysql table collation: https://stackoverflow.com/questions/2876789/how-can-i-search-case-insensitive-in-a-column-using-like-wildcard
Without changing database you can set:
$col["dbname"] = "trees.`title` COLLATE UTF8_GENERAL_CI";
It will then use above string in WHERE clause field name.

2) f.rules.push({field:"certificate",op:"bw",data:searchFiler});
Change "bw" to "cn" (begins with to contains)

Gabriel Brezuica answered 7 years ago

Abu,

The solution for the 2) point its ok, thank you a lot!

But with 1) … I think the problem is not in the query, because this is done beforehand and then I load the data from an array. I thought of a possible solution, which is to use an extra non-visible column with the Strings in lowercase (This is made easy with the function strtolower ()). Then, when typing the search, transform what is entered in the text box to lowercase, so that there is always a match.

In the code of my previous post (made in Javascript), How can I transform to lowercase the text to Search?

Thank's a lot.

Gabriel.

Gabriel Brezuica answered 7 years ago

Abu, I solved the problem. Just setting $grid["ignoreCase"] = true; the search turns case insensitive.

Thanks!

Abu Ghufran answered 7 years ago

Glad to know its fixed. I didn't knew you are using array based grid.

Your Answer

14 + 8 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?