asp.net mvc 3 - jqGrid saving a row with nullable columns -
so have jqgrid on asp.net mvc 3 website. it's loading data, searching, filtering, , saving rows built in pop-up editor. can't work saving nullable property. i'm using largejsonresult instead of built in jsonresult, example of row in grid this:
// c# class public class row { public string { get; set; } public string b { get; set; } public int c { get; set; } } // example object instance, let's these values come db var ret = new row { = "a", b = null, c = 5 }; // json string sent grid (notice b omitted) // "{ a: 'a', c: 5 }"
now, grid show as:
a b c undefined 5
and brings me problem. pop-up edit form show "undefined" in textbox b, , post server. if save database, i'll have "undefined" in db instead of null.
how jqgrid preserve null value round trip? 1 solution seems me hacky based on oleg solved in thread:
// override jqgrid serialization jquery.extend(jquery.jgrid.edit, { ajaxeditoptions: { contenttype: "application/json" }, serializeeditdata: function (data) { return json.stringify(data).replace(/"undefined"/g, 'null'); }});
this work, seems dangerous because it's doing mass edits of data without user's knowledge. in thinking more it, guess fundamental problem of saving null instead of "undefined" or other string representation of null (empty string, etc.). desired behavior be:
- if property null, , user doesn't change value, posts null
- if user changes value, property no longer null
can grid's edit form behave nullable properties? or have create custom edit form tracks user property?
i hope understand problem. in 1 applications used jqgrid had once problem null values. @ time of development of application not sure how solve problem , placed on server side text value "(null)" instead of null
value of 1 property. grid advanced users understand "(null)" is. value "(null)" has no sense in field (one had no user account name) , inside of server code edit operation distinguish "(null)" value real field value. in way come on problem.
in case should solve @ least 2 problems:
- you should decide how
null
value should displayed. "undefined" text seems me not best one. can solve problem "undefined" text either on server side (like did in case) or respect of custom formatter. custom formatter simple thing. define how cell value should displayed html fragment of<td>
contain. can example include additional hidden<span>
element or other html element or attribute save information valuenull
. - you should solve problem decoding of
null
value on server side during edit operations. can solve problem easy on server side (like compare of corresponding field "(null)") or respect of custom unformatter on client side. custom unformatter information grid cell (from hidden<span>
or other hidden html element or attribute) , place information in server request.
you can @ the demo the answer see example how 1 can use hidden <span>
save additional information in cell respect of custom formatter , read information later respect of custom unformatter.
Comments
Post a Comment