My data is being correctly loaded on my page. However I have 2 textboxes and one submit button based on which I want to filter the records from the server.
Note: I am not using existing filters functionality that is available with jqgrid by default.
I am little confused how can I achieve this. Is there any built in capability of jqgrid to achieve this? The way I currently handle this is I handle the click event in my javascript and supply post data to the action method:
$('#submit').click(function () {
$("#customers").jqGrid('setGridParam', { postData: { 'ContactName': $('#contactName').val(),
CompanyName: $('#companyName').val()
}
});
$("#customers").trigger("reloadGrid");
});
This post data is then being captured on action method and it works fine. Is there any better way of doing this? or am I on right track? Sometimes I feel I write less code on the server and have become more of a client side programmer since I started using Asp.Net MVC 3.0 😉
You don’t have to use setGridParam to change postData as you can declare a function :
so your submit function will only call to reloadGrid
If you want to reduce the amount of code, and you’d better create a simple API in JS to select entities like Customer, Person, Contact etc. Currently I have an app which forms consist of dozens such entities – so I had to create an JS API for selecting(it also gives universal look and feel). From the client side the customer specifies the name of list to get, while the list of possible names is defined in the server’s configuration file, which also defines the query to the ORM and how to display fields(I am using an expression language to map from entity fields to strings).