Hello,
We're using NetAdvantage for jQuery in an MVC2 environment. We have a Grid with row editing enabled, and ShowDoneCancelButtons set to false. All editable cells are numeric, so we're using the built in numeric editors. We're having a few issues and would like some assistance in resolving them:
1. Your documentation states that the 'Enter' key should trigger the EndUpdating event, and that 'Esc' should cancel it. However, it doesn't work unless we push 'Ctrl-Enter' or 'Ctrl-Esc'. Am I missing a setting?
2. To populate the grid, we are passing an IQueryable collection of complex objects. This fails if we create a GridModel and pass it to the view along with the data. It succeeds is we 'GET' an empty model, and then 'POST' and set the grid's DataSource to a JsonResult. This is less efficient than we would like
3. We would like to batch updates and are using the example shown @ https://www.igniteui.com/grid/basic-editing as a basis for our coding. After the post back, I can see the data for the 'dirty' rows in the ig_transactions request key, however, calling model.GetTransaction() does not populate embedded complex types (such as Foo.Bar.Foobar), and all embedded complex objects are set to initialized values instead of reflecting those being sent back from the UI.
Any assistance you could offer would be appreciated.
Thanks,Bob
Hi Bob,
regarding 1), i am using this sample, and i can see in the log everything works as expected:
https://www.igniteui.com/grid/editing-api-events
Which OS / browser are you using?
About 2) and 3), the grid doesn't support binding to nested (complex) properties at the moment, i suggest that you flatten this by creating classes which represent your model, and mapping the complex properties to those simple classes. We plan to have out of the box support for this in the next release.
Hope it helps. Thanks
Angel
Angel,
We're developing in .NET 3.5 using MVC 2. All users run windows 7 or XP SP 3 and we support IE 7 & 8 only.
Could you tell me in which JS file (unminified) and line number the editor key events are handled? Perhaps I can debug it here, and resolve. (We're currently waiting on a custom release to be built for us which you will be delivering the end of this month).
As to the complex objects, your "solution" is not an option for us. We're not going to change our object structures to conform to a 3rd party's limitations.
If anyone else in your user community is having the same issue, here's the fix:
Create a custom action filter, and a generic Complex Object Converter class and create the objects via reflection, using NewtonSoft's JSON library to handle the request params:
1. The Action Filter:
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext.HttpContext.Request.ContentType.Contains("application/json")) { JArray array; using (var sr = new StreamReader(filterContext.HttpContext.Request.InputStream)) { using (JsonTextReader jr = new JsonTextReader(sr)) { array = JArray.Load(jr); } } Result = new List<myComplexObject>(); foreach (JObject jObj in array) { var detail = ComplexObjectConverter<myComplexObject>.Convert(jObj); Result.Add(detail); } filterContext.ActionParameters[Param] = Result; } }
2. The complex object converter:
public class ComplexObjectConverter<T> { internal static T Convert(JObject jObj) { T result = (T)Activator.CreateInstance(typeof(T)); var pi = result.GetType().GetProperties(); foreach (KeyValuePair<string, JToken> key in jObj) { if (key.Key.IndexOf('.') == -1) { var p = pi.Single(m => m.Name == key.Key); p.SetValue(result, HandleCast(jObj[key.Key], p.PropertyType), null); } else { var nestedProp = key.Key.Split('.')[0]; var member = key.Key.Split('.')[1]; var pn = key.Key.Split('.'); object o = result; for (int i = 0; i < pn.Length - 1; i++) { o = TypeDescriptor.GetProperties(result)[pn[i]].GetValue(o); } var p = pi.Single(m => m.Name == nestedProp); var nv = p.PropertyType.GetProperties().Single(m => m.Name == member); TypeDescriptor.GetProperties(o)[pn[pn.Length - 1]].SetValue(o, HandleCast(jObj[key.Key], nv.PropertyType)); } } return result; } private static object HandleCast(JToken jToken, Type type) { if (type == typeof(int)) { return (int)jToken; } if (type == typeof(string)) { return jToken.ToString(); } if (type == typeof(decimal)) { return (decimal)jToken; } if (type == typeof(bool)) { return (bool)jToken; } throw new ArgumentException("type not found"); } Hopefully, this will help someone else.
public class ComplexObjectConverter<T> { internal static T Convert(JObject jObj) { T result = (T)Activator.CreateInstance(typeof(T)); var pi = result.GetType().GetProperties(); foreach (KeyValuePair<string, JToken> key in jObj) { if (key.Key.IndexOf('.') == -1) { var p = pi.Single(m => m.Name == key.Key); p.SetValue(result, HandleCast(jObj[key.Key], p.PropertyType), null); } else { var nestedProp = key.Key.Split('.')[0]; var member = key.Key.Split('.')[1]; var pn = key.Key.Split('.'); object o = result; for (int i = 0; i < pn.Length - 1; i++) { o = TypeDescriptor.GetProperties(result)[pn[i]].GetValue(o); } var p = pi.Single(m => m.Name == nestedProp); var nv = p.PropertyType.GetProperties().Single(m => m.Name == member); TypeDescriptor.GetProperties(o)[pn[pn.Length - 1]].SetValue(o, HandleCast(jObj[key.Key], nv.PropertyType)); } } return result; } private static object HandleCast(JToken jToken, Type type) { if (type == typeof(int)) { return (int)jToken; } if (type == typeof(string)) { return jToken.ToString(); } if (type == typeof(decimal)) { return (decimal)jToken; } if (type == typeof(bool)) { return (bool)jToken; } throw new ArgumentException("type not found"); }
Hopefully, this will help someone else.