Applying filters thru Jquery

QuestionsApplying filters thru Jquery
Chandru asked 12 years ago

Hi All,

I am not able to apply the filter to grid after using the below code in jquery script.
var myfilter = { groupOp: "AND", rules: []};
myfilter.rules.push({field:"Customer",op:"cn",data:"Cross"});
var grid = $("#list1");
grid.jqGrid({
search:true,
postData: { filters: myfilter}
//JSON.stringify(myfilter)
});
$('#list1').trigger("reloadGrid",[{jqgrid_page:1}]);

Anyone can help on this..
I am using the premium version.

Regards
Chandru

7 Answers
Abu Ghufran answered 12 years ago

Hello Chandru,

Try using this code …

<script>
var myfilter = { groupOp: "AND", rules: []};
myfilter.rules.push({field:"Customer",op:"cn",data:"Cross"});
var opts = {
search:true,
postData: { filters: myfilter}
};
</script>

<div style="margin:10px">
<?php echo $out?>
</div>

The var opts, override existing object's properties if any, when defined in this way.

Chandru answered 12 years ago

Hi Abu,

I have tried your option but i didnt succeed and in firebug it says like

_search true
filters[groupOp] AND
filters[rules][0][data] Cross
filters[rules][0][field] Customer
filters[rules][0][op] cn

Gives me error like "500 Internal Server Error -"

I want to apply filter and want to reload the grid using jquery.
or how can we pass columns and values to search option using jquery.

Regards
Chandru

Chandru answered 12 years ago

Hi Abu,

I am looking for something like this in php grid.
you can check this below demo
http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridFiltered.htm

is it possible that can we use the code like below in phpgrid.
$("#search").click(function() {
var searchFiler = $("#filter").val(), grid = $("#list"), f;

if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData,{filters:""});
}
f = {groupOp:"OR",rules:[]};
f.rules.push({field:"name",op:"cn",data:searchFiler});
f.rules.push({field:"note",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
grid.trigger("reloadGrid",[{page:1,current:true}]);
});

Regards
Chandru

Chandru answered 12 years ago

Hi Abu,

this script worked great for me..

$("#search").click(function() {
var searchFiler = $("#filter").val(), grid = $("#list"), f;

if (searchFiler.length === 0) {
grid[0].p.search = false;
$.extend(grid[0].p.postData,{filters:""});
}
f = {groupOp:"OR",rules:[]};
f.rules.push({field:"name",op:"cn",data:searchFiler});
f.rules.push({field:"note",op:"cn",data:searchFiler});
grid[0].p.search = true;
$.extend(grid[0].p.postData,{filters:JSON.stringify(f)});
grid.trigger("reloadGrid",[{page:1,current:true}]);
});

Regards
Chandur

Abu Ghufran answered 12 years ago

Hello Chandru,

I've sent you a working example code of it.

Regards

Ghaleb Dweikat answered 10 years ago

Is this feature available in the free version too? cuz I can't seem to get it to work and I always get this error:

Fatal error: Call to undefined function array_is_associative() (Error is in the jqgrid_dist.php on line 9)

this is the code I'm using:

<script type="text/javascript">
//var searchFiler = $("#Search").val();
var searchFiler = 'Admin';
var f;

f = { groupOp: "AND", rules: [] };
f.rules.push({ field: "Name", op: "cn", data: searchFiler });
//f.rules.push({field:"note",op:"cn",data:searchFiler});

var opts = {
search:true,
postData: { filters: f}
};
</script>

And I did place it before the echo of the $out

Abu Ghufran answered 10 years ago

I think, free version does not have this function. I'll need to update a build of free version to make it function.
I am emailing you a demo for an alternate solution.

Your Answer

2 + 13 =

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?