You probably have server-side problems. Could you please add your question with the DynamicGridData action code that you are currently using. The action must have filters as a parameter.
Some parts of your current code are completely wrong. For example, jqGrid is a jQuery plugin. Thus, jQuery methods will be expanded using the main jqGrid method, which you use as jQuery("#list").jqGrid(...); . Therefore, after initializing jqGrid jQuery("#list").jqGrid will be a function. In your code (the last statement), you rewrite the jQuery("#list").jqGrid method with the { search: { ... } } object. Instead you should
jQuery.extend(jQuery.jgrid.search, { odata : ['equal', 'not equal','contains'] });
as for example, it describes how to overwrite the default emptyrecords value. You do not need to include values ββthat already match in jqGrid's default settings.
In addition, if you use searchoptions: { sopt: ['eq', 'ne', 'cn']} for all columns available for search, you do not need to make changes.
In the text of your question you do not explain what you want. Your current code is for using the Message filter, which is true when loading the grid. The strange thing is that there is no column named Message in the table. If you just want to send additional information to the server, you better use the postData parameter:
postData: {Message:true}
I continue to recommend that you remove garbage from the jqGrid definition, for example imgpath and multipleSearch parameters jqGrid and sortable: true, search: true, sorttype: 'text', autoFit: true, stype:'text', align: 'left' , which are either unknown , or by default.
UPDATED . Source code The demo version of Phil Haack is very old and uses LINQ to SQL. As I already wrote (see here ) Entity Framework (EF) allows you to use sorting, swap and filter / search without any AddOns, such as LINQ Dynamic Query Library, in the form of System.Linq.Dynamic , So I did a demo you, which is a modification of the demo version of Phil Haack for EF.
Since you are using an old version of Visual Studio (VS2008 with ASP.NET MVC 2.0), I made a demo also in VS2008.
You can download the VS2008 demo from here and the VS2010 demo here .
In the code I'm showing (in addition to using the advanced search and toolbar search in ASP.NET MVC 2.0), how to return exception information from ASP.NET MVC in JSON format and how to catch information using loadError and display the corresponding error message .
To build Where the ObjectQuery statement represented by the EF object I define the following helper class:
public class Filters { public enum GroupOp { AND, OR } public enum Operations { eq, // "equal" ne, // "not equal" lt, // "less" le, // "less or equal" gt, // "greater" ge, // "greater or equal" bw, // "begins with" bn, // "does not begin with" //in, // "in" //ni, // "not in" ew, // "ends with" en, // "does not end with" cn, // "contains" nc // "does not contain" } public class Rule { public string field { get; set; } public Operations op { get; set; } public string data { get; set; } } public GroupOp groupOp { get; set; } public List<Rule> rules { get; set; } private static readonly string[] FormatMapping = { "(it.{0} = @p{1})", // "eq" - equal "(it.{0} <> @p{1})", // "ne" - not equal "(it.{0} < @p{1})", // "lt" - less than "(it.{0} <= @p{1})", // "le" - less than or equal to "(it.{0} > @p{1})", // "gt" - greater than "(it.{0} >= @p{1})", // "ge" - greater than or equal to "(it.{0} LIKE (@p{1}+'%'))", // "bw" - begins with "(it.{0} NOT LIKE (@p{1}+'%'))", // "bn" - does not begin with "(it.{0} LIKE ('%'+@p{1}))", // "ew" - ends with "(it.{0} NOT LIKE ('%'+@p{1}))", // "en" - does not end with "(it.{0} LIKE ('%'+@p{1}+'%'))", // "cn" - contains "(it.{0} NOT LIKE ('%'+@p{1}+'%'))" //" nc" - does not contain }; internal ObjectQuery<T> FilterObjectSet<T> (ObjectQuery<T> inputQuery) where T : class { if (rules.Count <= 0) return inputQuery; var sb = new StringBuilder(); var objParams = new List<ObjectParameter>(rules.Count); foreach (Rule rule in rules) { PropertyInfo propertyInfo = typeof (T).GetProperty (rule.field); if (propertyInfo == null) continue; // skip wrong entries if (sb.Length != 0) sb.Append(groupOp); var iParam = objParams.Count; sb.AppendFormat(FormatMapping[(int)rule.op], rule.field, iParam); // TODO: Extend to other data types objParams.Add(String.Compare(propertyInfo.PropertyType.FullName, "System.Int32", StringComparison.Ordinal) == 0 ? new ObjectParameter("p" + iParam, Int32.Parse(rule.data)) : new ObjectParameter("p" + iParam, rule.data)); } ObjectQuery<T> filteredQuery = inputQuery.Where (sb.ToString ()); foreach (var objParam in objParams) filteredQuery.Parameters.Add (objParam); return filteredQuery; } }
In this example, I use only two data types integer ( Edm.Int32 ) and string ( Edm.String ). You can easily extend this example to use more types based on propertyInfo.PropertyType.FullName , as indicated above.
The controller actions that provide data in jqGrid will be quite simple:
public JsonResult DynamicGridData(string sidx, string sord, int page, int rows, bool _search, string filters) { var context = new HaackOverflowEntities(); var serializer = new JavaScriptSerializer(); Filters f = (!_search || string.IsNullOrEmpty (filters)) ? null : serializer.Deserialize<Filters> (filters); ObjectQuery<Question> filteredQuery = (f == null ? context.Questions : f.FilterObjectSet (context.Questions)); filteredQuery.MergeOption = MergeOption.NoTracking;
To send the exception information to jqGrid in the form of JSON, I replaced the standard [HandleError] attribute of the controller ( HomeController ) with [HandleJsonException] , which I defined as the following:
// to send exceptions as json we define [HandleJsonException] attribute public class ExceptionInformation { public string Message { get; set; } public string Source { get; set; } public string StackTrace { get; set; } } public class HandleJsonExceptionAttribute : ActionFilterAttribute { // next class example are modification of the example from // the http://www.dotnetcurry.com/ShowArticle.aspx?ID=496 public override void OnActionExecuted(ActionExecutedContext filterContext) { if (filterContext.HttpContext.Request.IsAjaxRequest() && filterContext.Exception != null) { filterContext.HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; var exInfo = new List<ExceptionInformation>(); for (Exception ex = filterContext.Exception; ex != null; ex = ex.InnerException) { PropertyInfo propertyInfo = ex.GetType().GetProperty ("ErrorCode"); exInfo.Add(new ExceptionInformation() { Message = ex.Message, Source = ex.Source, StackTrace = ex.StackTrace }); } filterContext.Result = new JsonResult() {Data=exInfo}; filterContext.ExceptionHandled = true; } } }
On the client side, I used the following JavaScript code:
var myGrid = $('#list'), decodeErrorMessage = function(jqXHR, textStatus, errorThrown) { var html, errorInfo, i, errorText = textStatus + '\n' + errorThrown; if (jqXHR.responseText.charAt(0) === '[') { try { errorInfo = $.parseJSON(jqXHR.responseText); errorText = ""; for (i=0; i<errorInfo.length; i++) { if (errorText.length !== 0) { errorText += "<hr/>"; } errorText += errorInfo[i].Source + ": " + errorInfo[i].Message; } } catch (e) { } } else { html = /<body.*?>([\s\S]*)<\/body>/.exec(jqXHR.responseText); if (html !== null && html.length > 1) { errorText = html[1]; } } return errorText; }; myGrid.jqGrid({ url: '<%= Url.Action("DynamicGridData") %>', datatype: 'json', mtype: 'POST', colNames: ['Id', 'Votes', 'Title'], colModel: [ { name: 'Id', index: 'Id', key: true, width: 40, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] } }, { name: 'Votes', index: 'Votes', width: 40, searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'] } }, { name: 'Title', index: 'Title', width: 400, searchoptions: { sopt: ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'lt', 'le', 'gt', 'ge'] } } ], pager: '#pager', rowNum: 10, rowList: [5, 10, 20, 50], sortname: 'Id', sortorder: 'desc', rownumbers: true, viewrecords: true, altRows: true, altclass: 'myAltRowClass', height: '100%', jsonReader: { cell: "" }, caption: 'My first grid', loadError: function(jqXHR, textStatus, errorThrown) { // remove error div if exist $('#' + this.id + '_err').remove(); // insert div with the error description before the grid myGrid.closest('div.ui-jqgrid').before( '<div id="' + this.id + '_err" style="max-width:'+this.style.width+ ';"><div class="ui-state-error ui-corner-all" style="padding:0.7em;float:left;"><span class="ui-icon ui-icon-alert" style="float:left; margin-right: .3em;"></span><span style="clear:left">' + decodeErrorMessage(jqXHR, textStatus, errorThrown) + '</span></div><div style="clear:left"/></div>') }, loadComplete: function() { // remove error div if exist $('#' + this.id + '_err').remove(); } }); myGrid.jqGrid('navGrid', '#pager', { add: false, edit: false, del: false }, {}, {}, {}, { multipleSearch: true, overlay: false }); myGrid.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' }); myGrid.jqGrid('navButtonAdd', '#pager', { caption: "Filter", title: "Toggle Searching Toolbar", buttonicon: 'ui-icon-pin-s', onClickButton: function() { myGrid[0].toggleToolbar(); } });
As a result, if you type any non-numeric text (for example, "ttt") in the search bar, you get an exception action code for the controller (in Int32.Parse(rule.data) ). The following message appears on the client side:

I am sending information about all internal exceptions from the controller to jqgrid. So, for example, an error in connection with the SQL server will look like

In the real world, check the user login and throw an exception with an application error message. I didnβt specifically use such a check in the demo to show that all kinds of exceptions will be cached and displayed by jqGrid.
UPDATED 2 : In the answer you will find a modified demo version of VS2010 (can be downloaded from here ) that demonstrate the use of jQuery UI autocomplete. Another answer extends the code to export the grid in Excel format.