This is a migrated thread and some comments may be shown as answers.
Defining commands when autogenerating columns
16 Answers 153 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nohinn
Top achievements
Rank 1
Nohinn asked on 24 Jun 2011, 12:44 AM
I have read some other threads but it looks like I just cannot solve my problem.
I'm filling on server-side a datatable with the results from a sql query:
"SELECT * FROM ..."

As I really don't know what columns it may have so far, I set the grid to autogenerate them, that's working ok.
The problem is, I would like to let the users edit, delete, add... rows but anytime I try (using MVC3) I just get the error already posted in the forums that states:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

16 Answers, 1 is accepted

Sort by
0
Nohinn
Top achievements
Rank 1
answered on 24 Jun 2011, 11:01 AM
I did see the thread.
But it would come handy if I know which columns/property does the object have.
As I'm just building a DataTable from a sql query I do not know which columns/properties does each row object have.

By the way, I forgot to say, I'm using VB so no use of dynamic keyword, etc.
0
Nohinn
Top achievements
Rank 1
answered on 24 Jun 2011, 07:22 PM
Ok, reading through the forums I found a thread where a telerik developer says you cannot make a grid editable while using a datatable (though they were talking about MVC2 I don't know if something changed about this for MVC3).

Anyway, there is any workaround I may use so I could let users edit the grid which does not use a compiled class but something dynamic?
0
Nohinn
Top achievements
Rank 1
answered on 26 Jun 2011, 12:26 AM
I'm sorry for posting so many posts, but I would like to get an answer about this question I will do right now:
if I make a dynamic class using reflection and emit, there is any way I could use that as the source for the grid?
While debugging in visual studio I can see the source of the grid has the dynamic properties I have defined, but the grid apparently cannot autogenerate them nor I can if I use a column name I know that exists in the resulting dynamic object with the Bound function:
c.Bound("ColumnThatExists")

This will just throw an exception saying that the configurator parameter could not be converted from 'VB$AnonymousDelegate_2(Of Object)' to 'Action(Of GridColumnFactory(Of MyDataObject))'
0
Atanas Korchev
Telerik team
answered on 27 Jun 2011, 07:41 AM
Hello Nohinn,

 We have not tested the grid with dynamic classes generated via reflection emit. The grid looks for all public properties of primitive types and creates columns for those.

 You may want to check the following code library projects:

 Editing with DataTable
 Editing with dynamic 

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 27 Jun 2011, 10:39 AM
Thanks, I do see that I don't get any error using InForm as edit mode, but if I try to use InLine edit mode I get the error, there is any possibility of using InLine edit mode with a datatable?
0
Rosen
Telerik team
answered on 28 Jun 2011, 07:45 AM
Hello Nohinn,

Unfortunately, this is not currently possible due to the quite limited support for DataTables in the MVC framework itself.

Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 04 Jul 2011, 09:23 AM
after some crazy days, I got my grid working using codedom (for the type class to be used on the grid) + reflection (to make the grid capable of using this runtime class).
However now I'm getting a little javascript error:
function w(E){var B={};for(var A=0;A<E.length;A++){var D=E[A];var C=D.FieldName;B[C]=y(D)}return B}

the error is in the for loop, E comes as 'undefined' so it cannot get the length of the object, the result after just ignoring this error is the grid as it is at the beginning but with the update and cancel buttons instead of the edit button.

I think it must be related to any javascript file missing (maybe), I tried to use the grid.editing javascript file version not minified but then it would not send a request to fill the grid at the beginning with ajax.

these are the scripts I'm using right now:
"telerik.common.min.js"
"telerik.textbox.min.js"
"telerik.calendar.min.js"
"telerik.datepicker.min.js"
"telerik.draganddrop.min.js"
"telerik.grid.min.js"
"telerik.grid.grouping.min.js"
"telerik.grid.resizing.min.js"
"telerik.grid.reordering.min.js"
"telerik.grid.filtering.min.js"
"telerik.grid.editing.min.js"
0
Rosen
Telerik team
answered on 04 Jul 2011, 10:05 AM
Hello Nohinn,

The missing script from the list you have pasted is jquery.validate, however I'm not sure if this is the cause for the error you are getting using the provided information.

Regards,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 04 Jul 2011, 10:49 AM
Sorry, I had the jquery required files included too, but I only posted the telerik script files I was using.
In fact it looks like it is related to the validation, this is the complete line where the error is produced:

(function(h){var c=h.telerik,j=/^\/Date\((.*?)\)\/$/;var g=function(l){this.formId=l;this._isBuild=false;var n="tUnobtrusiveValidation";var m="tUnobtrusiveContainer";var k=this.unobtrusive={adapters:[],parseElement:function(o,r){var p=h(o),q=p.parents("form")[0],t,s,u;if(!q){return}t=k.validationInfo(q);t.options.rules[o.name]=s={};t.options.messages[o.name]=u={};h.each(this.adapters,function(){var v="data-val-"+this.name,w=p.attr(v),x={};if(w!==undefined){v+="-";h.each(this.params,function(){x[this]=p.attr(v+this)});this.adapt({element:o,form:q,message:w,params:x,rules:s,messages:u})}});if(!r){t.attachValidation()}},parse:function(o){h(o).find(":input[data-val=true]").each(function(){k.parseElement(this,true)});h("form").each(function(){var p=k.validationInfo(this);if(p){p.attachValidation()}})},onError:function(o,r){var q=h(this).find("[data-valmsg-for='"+r[0].name+"']"),p=h.parseJSON(q.attr("data-valmsg-replace"))!==false;q.removeClass("field-validation-valid").addClass("field-validation-error");o.data(m,q);if(p){q.empty();o.removeClass("input-validation-error").appendTo(q)}else{o.hide()}},onErrors:function(o,r){var q=h(this).find("[data-valmsg-summary=true]"),p=q.find("ul");if(p&&p.length&&r.errorList.length){p.empty();q.addClass("validation-summary-errors").removeClass("validation-summary-valid");h.each(r.errorList,function(){h("<li />").html(this.message).appendTo(p)})}},onSuccess:function(o){var q=o.data(m),p=h.parseJSON(q.attr("data-valmsg-replace"));if(q){q.addClass("field-valiion-valid").removeClass("field-validation-error");o.removeData(m);if(p){q.empty()}}},validationInfo:function(o){var q=h(o),p=q.data(n);if(!p){p={options:{errorClass:"input-validation-error",errorElement:"span",errorPlacement:h.proxy(k.onError,o),invalidHandler:h.proxy(k.onErrors,o),messages:{},rules:{},success:h.proxy(k.onSuccess,o)},attachValidation:function(){q.validate(this.options)},validate:function(){q.validate();return q.valid()}};q.data(n,p)}return p}}};g.prototype={build:function(){if(this._isBuild){return}this._isBuild=true;var o=[];function m(r,q,p){r.rules[q]=p;if(r.message){r.messages[q]=r.message}}function n(p){return p.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function l(p){return p.substr(0,p.lastIndexOf(".")+1)}function k(q,p){if(q.indexOf("*.")===0){q=q.replace("*.",p)}return q}o=this.unobtrusive.adapters;o.add=function(r,q,p){if(!p){p=q;q=[]}this.push({name:r,params:q,adapt:p});return this};o.addBool=function(q,p){return this.add(q,function(r){m(r,p||q,true)})};o.addMinMax=function(s,q,u,p,r,t){return this.add(s,[r||"min",t||"max"],function(x){var v=x.params.min,w=x.params.max;if(v&&w){m(x,p,[v,w])}else{if(v){m(x,q,v)}else{if(w){m(x,u,w)}}}})};o.addSingleVal=function(q,r,p){return this.add(q,[r||"val"],function(s){m(s,p||q,s.params[r])})};o.addSingleVal("accept","exts").addSingleVal("regex","pattern");o.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");o.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range");o.add("equalto",["other"],function(q){var p=h(q.form).find(":input[name="+q.params.other+"]")[0];m(q,"equalTo",p)});o.add("required",function(p){if(p.element.tagName.toUpperCase()!=="INPUT"||p.element.type.toUpperCase()!=="CHECKBOX"){m(p,"required",true)}});o.add("remote",["url","type","additionalfields"],function(r){var p={url:r.params.url,type:r.params.type||"GET",data:{}},q=l(r.element.name);h.each(n(r.params.additionalfields||r.element.name),function(s,u){var t=k(u,q);p.data[t]=function(){return h(r.form).find(":input[name='"+t+"']").val()}});m(r,"remote",p)});if(h.validator.unobtrusive&&h.validator.unobtrusive.adapters){h.extend(o,h.validator.unobtrusive.adapters)}h.validator.addMethod("regex",function(p,r,q){if(this.optional(r)){return true}var s=new RegExp(q).exec(p);return s&&s.index==0&&s[0].length==p.length});h.validator.addMethod("number",function(p,s){var q=c.cultureInfo.numericgroupsize;var r=new c.stringBuilder();r.cat("^-?(?:\\d+|\\d{1,").cat(q).cat("}(?:").cat(c.cultureInfo.numericgroupseparator).cat("\\d{").cat(q).cat("})+)(?:\\").cat(c.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(s)||new RegExp(r.string()).test(p)})},parse:function(){this.build();this.unobtrusive.parse(this.formId)}};var f=function(k){this.validationMetaData=k};f.prototype={build:function(o){h.validator.addMethod("regex",function(A,C,B){if(this.optional(C)){return true}var D=new RegExp(B).exec(A);return D&&D.index==0&&D[0].length==A.length});h.validator.addMethod("number",function(A,D){var B=c.cultureInfo.numericgroupsize;var C=new c.stringBuilder();C.cat("^-?(?:\\d+|\\d{1,").cat(B).cat("}(?:").cat(c.cultureInfo.numericgroupseparator).cat("\\d{").cat(B).cat("})+)(?:\\").cat(c.cultureInfo.numericdecimalseparator).cat("\\d+)?$");return this.optional(D)||new RegExp(C.string()).test(A)});function t(B,A,C){B.range=[A,C]}function p(A,B){A.regex=B}function z(A){A.required=true}function v(A,B){A.maxlength=B}function m(A,B,C){A[B]=C}function x(D){var A={};for(var C=0;C<D.length;C++){var B=D[C];A[B.FieldName]="#"+B.ValidationMessageId}return A}function n(A){var I={};for(var B=0;B<A.length;B++){var G=A[B];var H={};I[G.FieldName]=H;var E=G.ValidationRules;for(var C=0;C<E.length;C++){var D=E[C];if(D.ErrorMessage){var F=D.ValidationType;switch(D.ValidationType){case"regularExpression":F="regex";break;case"stringLength":F="maxlength";break}H[F]=D.ErrorMessage}}}return I}function y(F){var D=F.ValidationRules;var E={};for(var A=0;A<D.length;A++){var C=D[A];switch(C.ValidationType){case"range":var B=(typeof(C.ValidationParameters.minimum)=="undefined")?C.ValidationParameters.min:C.ValidationParameters.minimum;var G=(typeof(C.ValidationParameters.maximum)=="undefined")?C.ValidationParameters.max:C.ValidationParameters.maximum;t(E,B,G);break;case"regularExpression":case"regex":p(E,C.ValidationParameters.pattern);break;case"required":z(E);break;case"stringLength":v(E,C.ValidationParameters.maximumLength);break;case"length":v(E,C.ValidationParameters.max);break;default:m(E,C.ValidationType,C.ValidationParameters);break}}return E}function w(E){var B={};for(var A=0;A<E.length;A++){var D=E[A];var C=D.FieldName;B[C]=y(D)}return B}var k=h("#"+o.FormId);var s=o.Fields;var l=w(s);var r=x(s);var u=n(s);var q={errorClass:"input-validation-error",errorElement:"span",errorPlacement:function(A,B){var C=r[B.attr("name")];if(C){h(C).empty().removeClass("field-validation-valid").addClass("field-validation-error");A.removeClass("input-validation-error").attr("_for_validation_message",C).appendTo(C)}},messages:u,rules:l,success:function(A){h(A.attr("_for_validation_message")).empty().addClass("field-validation-valid").removeClass("field-validation-error")}};k.validate(q)},parse:function(){this.build(this.validationMetaData)}};c.editing={};function b(){h(document.body).find("div.t-grid").each(function(){var k=h(this).data("tGrid");if(k&&k.cancel){k.cancel()}})}function a(l,k,m){for(var n in k){if(h.isPlainObject(k[n])){a(l,k,m?prefx+"."+n:n)}else{l[m?m+"."+n:n]=k[n]}}}function i(k){for(var o in k){var n=o.indexOf(".");if(n>-1){var m=o.substring(0,n);var l=k[m]||{};l[o.substring(n+1)]=k[o];k[m]=i(l);delete k[o]}}return k}function d(l){var m,k,n;for(m in l){k=l[m];if(typeof k==="string"){n=j.exec(k);if(n){l[m]=new Date(parseInt(n[1]))}}else{if(h.isPlainObject(k)){d(k)}}}}c.editing.initialize=function(l){h.extend(l,this.implementation);var k=h(l.element);l.modelBinder=new c.grid.ModelBinder();l.formViewBinder=new c.grid.FormViewBinder({date:function(v,s){var u=l.columnFromMember(v);var t=u?u.format:"";return c.formatString(t||"{0:G}",s)}});if(l.isAjax()){if(l.editing.mode=="InCell"){d(l.editing.defaultDataItem||{});l.changeLog=new c.grid.ChangeLog(l.pageSize||(l.data&&l.data.length)||0);h(l.element).bind("dataBound",function(){l.changeLog.clear()});l.cellEditor=new c.grid.CellEditor({columns:l.columns,cellIndex:function(s){return l.cellIndex(s)},id:l.formId(),bind:h.proxy(l.formViewBinder.bind,l.formViewBinder),validate:h.proxy(l.validation,l)});k.delegate(".t-grid-save-changes:not(.t-state-disabled)","click",c.stopAll(function(s){l.submitChanges()}));k.delegate(".t-grid-cancel-changes","click",c.stopAll(function(s){l.cancelChanges()}));l.hasChanges=function(){return l.changeLog.dirty()};l.submitChanges=function(){if(l.changeLog.dirty()){var s=l.changeLog.inserted;var u=h.grep(l.changeLog.updated,function(w){return w!=undefined});var t=h.grep(l.changeLog.deleted,function(w){return w!=undefined});if(c.trigger(l.element,"submitChanges",{inserted:s,updated:u,deleted:t})){return}var v=l.ws?{inserted:h.map(s,function(w){return l._convert(w)}),updated:h.map(u,function(w){return l._convert(w)}),deleted:h.map(t,function(w){return l._convert(w)})}:l.changeLog.serialize(s,u,t);l.sendValues(v,"updateUrl")}};l.cancelChanges=function(){l.changeLog.clear();l.dataBind(l.data.slice(0));l.valid=true};l.cellIndex=function(s){return h(s).parent().find("td:not(.t-group-cell,.t-hierarchy-cell)").index(s)};l.rowIndex=function(s){return h(s).parent().find("tr:not(.t-detail-row,.t-grouping-row)").index(s)};var p;l.valid=true;l.editCell=function(v){var s=l.columns[l.cellIndex(v)];if(l.valid&&(s&&!s.readonly)){l.td=v;v=h(v);var u=v.parent();var w=l.rowIndex(u);var t=l.changeLog.get(w)||l.dataItem(u);p=v.find(".t-dirty");l.cellEditor.edit(v,t);c.trigger(l.element,"edit",{mode:u.hasClass("t-grid-new-row")?"insert":"edit",form:l.form()[0],dataItem:t,cell:v[0]})}};l.saveCell=function(v){l.valid=l.validate();if(l.valid){v=h(v);var u=v.parent();var t=l.dataItem(u);var w=i(l.modelBinder.bind(v));var s=false;if(c.trigger(l.element,"save",{mode:u.hasClass("t-grid-new-row")?"insert":"edit",dataItem:t,values:w,form:l.form()[0],cell:v[0]})){return}if(u.hasClass("t-grid-new-row")){l.changeLog.insert(l.rowIndex(u),w)}else{s=l.changeLog.update(l.rowIndex(u),t,w)}l.cellEditor.display(v,w);if(s||u.hasClass("t-grid-new-row")){p=h('<span class="t-dirty" />')}if(p&&p.length){p.prependTo(l.td)}l.td=null}};l.td=null;l.$tbody.delegate("tr:not(.t-grouping-row) > td:not(.t-detail-cell,.t-grid-edit-cell,.t-group-cell,.t-hierarchy-cell)",l.editing.beginEdit||"click",function(s){if(h(this).closest("tbody")[0]==l.$tbody[0]){l.editCell(this)}});h(document).mousedown(function(s){if(l.td&&!h.contains(l.td,s.target)&&l.td!=s.target&&!h(s.target).closest(".t-animation-container").length){l.saveCell(l.td)}})}else{if(l.editing.beginEdit){l.$tbody.delegate("tr:not(.t-detail-row,.t-grouping-row,.t-grid-edit-row,.t-group-footer)",l.editing.beginEdit,function(s){if(!h(s.target).is(":button,a,:input,a>.t-icon")){l.editRow(h(this))}})}}k.delegate(".t-grid-edit","click",c.stopAll(function(s){l.editRow(h(this).closest("tr"))})).delegate(".t-grid-delete","click",c.stopAll(function(s){l.deleteRow(h(this).closest("tr"))})).delegate(".t-grid-add","click",c.stopAll(function(s){l.addRow()}))}else{k.delegate(".t-grid-delete","click",c.stop(function(s){if(l.editing.confirmDelete!==false&&!confirm(l.localization.deleteConfirmation)){s.preventDefault()}}));l.validation()}l.errorView=new c.grid.ErrorView();var r=new c.grid.DataCellBuilder({columns:l.columns});var m=h.grep(l.columns,function(s){return s.commands&&h.grep(s.commands,function(t){return t.name=="edit"})[0]})[0];if(!m){m={commands:[{name:"edit",buttonType:"Text"}]};m.insert=l.insertFor(m);m.edit=l.editFor(m)}var n=new c.grid.FormContainerBuilder({html:function(){return unescape(l.editing.editor)},insert:function(){return m.insert()},edit:function(){return m.edit()}});var q=l.editing.mode;var o=function(){return(l.groups||[]).length};if(q=="InLine"){l.rowEditor=new c.grid.Editor({id:l.formId(),cancel:r.display,edit:r.edit,insert:r.insert,groups:o,details:l.detail})}else{if(q=="InForm"){l.rowEditor=new c.grid.Editor({id:l.formId(),cancel:r.display,groups:o,details:l.detail,edit:function(){return'<td colspan="'+l.columns.length+'">'+n.edit()+"</td>"},insert:function(){return'<td colspan="'+l.columns.length+'">'+n.insert()+"</td>"}})}else{if(q=="PopUp"){l.rowEditor=new c.grid.PopUpEditor({id:l.formId(),edit:n.edit,container:l.element,settings:l.editing.popup,insert:n.insert,editTitle:l.localization.edit,insertTitle:l.localization.insert})}else{r=new c.grid.CellBuilder({columns:l.columns});l.rowEditor=new c.grid.Editor({id:l.formId(),cancel:r.display,edit:r.edit,insert:r.insert})}}}k.delegate(":input:not(.t-button):not(textarea)","keydown",function(t){if(t.keyCode==13||t.keyCode==27){t.preventDefault();var s={13:".t-grid-update, .t-grid-insert",27:".t-grid-cancel"};h(this).closest("tr").find(s[t.keyCode]).click()}})};c.editing.implementation={editFor:function(l){var m=this.localization;if(l.commands){var o=h.grep(l.commands,function(q){return q.name=="edit"})[0];if(o){var p=c.grid.ButtonBuilder.create(h.extend({text:m.update},o,{name:"update"}));var n=c.grid.ButtonBuilder.create(h.extend({text:m.cancel},o,{name:"cancel"}));var k=p.build()+n.build();return function(){return k}}else{return function(){return""}}}else{if(!l.readonly&&l.editor){return function(){return unescape(l.editor)}}}return this.displayFor(l)},insertFor:function(l){var m=this.localization;if(l.commands){var o=h.grep(l.commands,function(q){return q.name=="edit"})[0];if(o){var p=c.grid.ButtonBuilder.create(h.extend({text:m.insert},o,{name:"insert"}));var n=c.grid.ButtonBuilder.create(h.extend({text:m.cancel},o,{name:"cancel"}));var k=p.build()+n.build();return function(){return k}}else{return function(){return""}}}else{return this.editFor(l)}},insertRow:function(k){if(this.validate()){var l=this.extractValues(k);if(c.trigger(this.element,"save",{mode:"insert",values:l,form:this.form()[0]})){return}this.sendValues(l,"insertUrl")}},updateRow:function(k){if(this.validate()){var l=this.dataItem(k.data("tr")||k);var m=this.extractValues(k,(this.editing.mode!="InCell"||!this.ws));if(c.trigger(this.element,"save",{mode:"edit",dataItem:l,values:m,form:this.form()[0]})){return}if(this.editing.mode=="InCell"){m=h.extend(l,m)}d(m);this.sendValues(m,"updateUrl")}},deleteRow:function(k){var l=this.dataItem(k);if(this.editing.mode!="InCell"){if(c.trigger(this.element,"delete",{dataItem:l})){return}if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.sendValues(this.extractValues(k,true),"deleteUrl")}}else{if(this.editing.confirmDelete===false||confirm(this.localization.deleteConfirmation)){this.changeLog.erase(this.rowIndex(k),l);this.td=null;this.cancelRow(k);k.hide()}}},editRow:function(k){var m=this.dataItem(k);if(this.editing.mode!="InCell"){b();var n=this.rowEditor.edit(k,m);var l=this.form();l.undelegate(".t-grid-update").delegate(".t-grid-update","click",c.stopAll(h.proxy(function(){this.updateRow(n)},this))).undelegate(".t-grid-cancel").delegate(".t-grid-cancel","click",c.stopAll(h.proxy(function(){this.cancelRow(k)},this)));this.formViewBinder.bind(n,m);c.trigger(this.element,"edit",{mode:"edit",form:l[0],dataItem:m});this.validation()}else{if(this.valid){this.rowEditor.edit(k,m);this.td=row.find(":input:visible:first").focus().closest("td")[0];this.validation()}}},form:function(){return h("#"+this.formId())},addRow:function(){var n=h.extend(true,{},this.editing.defaultDataItem);if(this.editing.mode!="InCell"){b();var p=this.rowEditor.insert(this.$tbody,n);var l=this.form();l.undelegate(".t-grid-insert").delegate(".t-grid-insert","click",c.stopAll(h.proxy(function(){this.insertRow(p)},this))).undelegate(".t-grid-cancel").delegate(".t-grid-cancel","click",c.stopAll(h.proxy(function(){this.cancelRow(p)},this)));c.trigger(this.element,"edit",{mode:"insert",form:l[0]});this.validation()}else{if(this.valid){var m=this.rowEditor.insert(this.$tbody,n);this.changeLog.insert(n);this.td=m.find(":input:enabled:visible:first").focus().closest("td")[0];for(var k=this.columns.length-1;k>=0;k--){if(!this.columns[k].readonly){var o=m.children().eq(k);if(o[0]!=this.td){o.prepend('<span class="t-dirty" />')}}}this.validation()}}},extractValues:function(p,m){var n=this.modelBinder.bind(p);if(m){var o=this.dataItem(p.data("tr")||p);for(var l in this.dataKeys){var k=this.valueFor({member:l})(o);if(k instanceof Date){k=c.formatString("{0:G}",k)}n[this.ws?l:this.dataKeys[l]]=k}}return n},cancelRow:function(k){if(!k.length){return}var l=this.dataItem(k);this.rowEditor.cancel(k,l);if(k.is(".t-grid-new-row")){return}c.trigger(this.element,"rowDataBound",{row:k[0],dataItem:l})},validate:function(){var k=this.form();if(k.length){var m=k.validate();var l=m.form();if(m.pendingRequest){m.formSubmitted=true;return false}return l}return true},cancel:function(){this.cancelRow(this.$tbody.find(">.t-grid-edit-row"))},_convert:function(o){for(var l in o){var k=o[l];if(k instanceof Date){var n=this.columnFromMember(l);var m="{0:G}";if(n&&n.format){m=n.format}o[l]=this.ws?"\\/Date("+k.getTime()+")\\/":c.formatString(m,k)}if(k==undefined){delete o[l]}if(h.isPlainObject(k)){this._convert(k)}}return o},sendValues:function(n,k){if(this.editing.mode!="InCell"||!this.ws){this._convert(n);for(var l in this.dataKeys){var m=this.valueFor({member:l})(n);if(m!=undefined){n[this.ws?l:this.dataKeys[l]]=m}}}h.ajax(this.ajaxOptions({data:this.ws?(this.editing.mode=="InCell"?n:{value:n}):n,url:this.url(k),hasErrors:h.proxy(this.hasErrors,this),displayErrors:h.proxy(this.displayErrors,this)}))},displayErrors:function(k){this.errorView.bind(h("#"+this.formId()),k.modelState)},hasErrors:function(k){var l=k.modelState;var m=false;if(l){h.each(l,function(n,o){if("errors" in o){m=true;return false}})}return m},formId:function(){return h(this.element).attr("id")+"form"},validation:function(){this.validator().parse()},validator:function(){if(this.validationMetadata){return new f(this.validationMetadata)}else{return new g(h("#"+this.formId()))}}};c.grid.ModelBinder=function(){this.binders={":input.t-autocomplete":function(){return h(this).val()},".t-numerictextbox :input":function(){return h(this).val()},":input:not(.t-input):not(:radio),:radio:checked":function(){return h(this).val()},":checkbox":function(){return h(this).is(":checked")},".t-datepicker :input":function(){return h(this).data("tDatePicker").value()},".t-timepicker :input":function(){return h(this).data("tTimePicker").value()},".t-datetimepicker :input":function(){return h(this).data("tDateTimePicker").value()},".t-editor textarea:hidden":function(){var k=h(this).closest(".t-editor").data("tEditor");if(k.encoded){return k.encodedValue()}return k.value()}};this.bind=function(k){var l={};h.each(this.binders,function(m,n){k.find(m).each(function(){if(!this.disabled){l[this.name]=n.call(this)}})});return l}};c.grid.FormViewBinder=function(m){this.converters=m||{};this.binders={":input:not(:radio)":function(n){if(typeof n=="boolean"){n=n+""}h(this).val(n)},":checkbox":function(n){h(this).attr("checked",n==true)},":radio":function(o){var n=h(this).val();if(typeof o=="boolean"){n=n.toLowerCase()}if(n==o.toString()){h(this).attr("checked",true)}}};function l(n){return function(o){h(this).data(n).value(o)}}function k(){return function(n){h(this).closest(".t-editor").data("tEditor").value(n)}}this.binders[".t-numerictextbox :input"]=l("tTextBox");this.binders[".t-dropdown :input:hidden"]=l("tDropDownList");this.binders[".t-datepicker :input"]=l("tDatePicker");this.binders[".t-datetimepicker :input"]=l("tDateTimePicker");this.binders[".t-combobox :input:hidden"]=l("tComboBox");this.binders[".t-editor textarea:hidden"]=k();this.evaluate=function(o,r){if(r!=null){var n=o,p=false,t=r.split(".");while(t.length){var u=t.shift();if(n!=null&&typeof(n[u])!="undefined"){n=n[u];p=true}else{if(p){p=false;break}}}if(p&&!h.isPlainObject(n)){var q=j.exec(n);if(q){n=new Date(parseInt(q[1]))}var s=c.getType(n);if(s in this.converters){n=this.converters[s](r,n)}return n}}};this.bind=function(p,o){var n;h.each(this.binders,h.proxy(function(q,r){p.find(q).each(h.proxy(function(t,u){var s=this.evaluate(o,u.name);if(s!=n){r.call(u,s)}},this))},this))}};c.grid.CellBuilder=function(k){function l(n,m){return h.map(k.columns,function(p,o){return"<td "+(p.attr?p.attr:"")+(o==k.columns.length-1?' class="t-last">':">")+p[o==0?m:"display"](n)+"</td>"}).join("")}this.edit=function(m){return l(m,"edit")};this.insert=function(m){return l(m,"insert")};this.display=function(m){return l(m,"display")}};c.grid.DataCellBuilder=function(k){function l(n,m){return h.map(k.columns,function(p,o){return"<td "+(p.attr?p.attr:"")+(o==k.columns.length-1?' class="t-last">':">")+p[m](n)+"</td>"}).join("")}this.edit=function(m){return l(m,"edit")};this.insert=function(m){return l(m,"insert")};this.display=function(m){return l(m,"display")}};c.grid.FormContainerBuilder=function(k){function l(m){return'<div class="t-edit-form-container">'+k.html()+k[m]()+"</div>"}this.edit=function(){return l("edit")};this.insert=function(){return l("insert")}};function e(k){return h("<form />",{className:"t-edit-form",id:k}).submit(c.preventDefault)}c.grid.PopUpEditor=function(m){var l;function k(){var o=l.data("tWindow");o&&o.close();l.remove()}function n(p,o){l=h("<div />",{id:m.container.id+"PopUp"}).appendTo(m.container).css({top:0,left:"50%",marginLeft:-90}).tWindow(m.settings).find(".t-window-content").append(m[o](p)).wrapInner(e(m.id)).end();h(m.container).one("dataBound",k);l.find("t-close").bind("close",c.stopAll(k)).end().data("tWindow").open().title(m[o+"Title"]);return l}this.edit=function(o,p){o.addClass("t-grid-edit-row");return n(p,"edit").data("tr",o)};this.insert=function(o,p){return n(p,"insert")};this.cancel=function(o){o.removeClass("t-grid-edit-row");k()}};c.grid.Editor=function(m){var l=m.groups||function(){return 0};function k(n,o,p){var q=n.find(".t-group-cell,.t-hierarchy-cell");n.addClass("t-grid-edit-row").empty().append(q).append(m[p](o)).closest("table").wrap(function(){if(!h(this).parent().is("form")){return e(m.id)}})}this.cancel=function(n,o){if(n.is(".t-grid-new-row")){n.remove()}else{k(n,o,"cancel");n.removeClass("t-grid-edit-row")}};this.insert=function(p,o){var q='<tr class="t-grid-new-row">'+new Array(l()+1).join('<td class="t-group-cell" />')+((m.details)?'<td class="t-hierarchy-cell"/>':"")+"</tr>";var n=h(q);p.prepend(n);k(n,o,"insert");return n};this.edit=function(n,o){k(n,o,"edit");return n}};c.grid.CellEditor=function(k){this.edit=function(n,m){var l=k.columns[k.cellIndex(n)];if(!l.readonly){n.parent().addClass("t-grid-edit-row").end().empty().html(l.edit(m)).closest("table").wrap(function(){if(!h(this).parent().is("form")){return e(k.id)}});k.bind(n,m);k.validate();n.find(":input:visible:first").trigger("focusin").focus();n.addClass("t-grid-edit-cell")}return !l.readonly};this.display=function(n,m){var l=k.columns[k.cellIndex(n)];n.removeClass("t-grid-edit-cell").empty().html(l.display(m)).parent().removeClass("t-grid-edit-row")}};c.grid.ChangeLog=function(l){this.insert=function(m,o){if(o==undefined){o=m;this.inserted.splice(0,0,o)}else{var n=this.inserted[m];if(n===undefined){this.inserted.splice(0,0,o)}else{h.extend(n,o)}}};this.get=function(n){var m=this.inserted[n];if(this.inserted[n]){return m}return this.updated[n-this.inserted.length]};this.update=function(s,p,o){s=s-this.inserted.length;var t=this.updated[s]||p||{};var r=false;for(var m in o){var q=t[m],n=o[m];if(q instanceof Date){if(n.getTime()!==q.getTime()){r=true}}else{if(n!==q){r=true}}}if(r){this.updated[s]=h.extend({},t,o)}return r};this.erase=function(n,p){var m=this.inserted[n];if(m){this.inserted.splice(n,1)}else{n=n-this.inserted.length;var o=this.updated[n];if(o){delete this.updated[n]}this.deleted[n]=p}};this.clear=function(){this.updated=new Array(l);this.deleted=new Array(l);this.inserted=[]};function k(n,r,t){var u={};for(var s=0,o=0;s<n.length;s++){var q=n[s];if(t(q)){for(var m in q){var p=q[m],v=r+"["+o+"]."+m;if(h.isPlainObject(p)){a(u,p,v)}else{u[v]=p}}o++}}return u}this.serialize=function(m,o,n){return h.extend({},k(m,"inserted",function(){return true}),k(o,"updated",function(p){return p!==undefined}),k(n,"deleted",function(p){return p!==undefined}))};this.dirty=function(){if(this.inserted.length){return true}for(var m=0;m<this.updated.length;m++){if(this.updated[m]){return true}}for(m=0;m<this.deleted.length;m++){if(this.deleted[m]){return true}}return false};this.clear()};c.grid.ErrorView=function(){this.bind=function(k,l){k.find("span[id$=_validationMessage]").removeClass("field-validation-error").addClass("field-validation-valid").html("").end().find(".input-validation-error").removeClass("input-validation-error").addClass("valid");h.each(l,function(o,m){if("errors" in m&&m.errors[0]){var n=o;o=o.replace(".","_");k.find("#"+o+'_validationMessage, [data-valmsg-for="'+n+'"]').html(m.errors[0]).removeClass("field-validation-valid").removeClass("field-valiion-valid").addClass("field-validation-error").end().find("#"+o).removeClass("valid").addClass("input-validation-error")}})}}})(jQuery);

I think it tries to get a length for something, maybe a minlength or maxlength or something, then it calls the function where the for loop is producing the error.
I don't know if this could be bypassed somehow or what I may be doing wrong.
I'm populating this reflected grid from a datatable.
The code I'm using has telerik's source modified to make some constructors public, so I don't know if there is any problem about posting it. So I will wait for an answer before.
0
Atanas Korchev
Telerik team
answered on 04 Jul 2011, 11:43 AM
Hello Nohinn,

 You have pasted the whole minified telerik.grid.editing.js file. This will not help us find the problem. You can try using the unminifed telerik.grid.editning.js which is distributed with the source code.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 04 Jul 2011, 12:17 PM
function createValidationOptions(validationFields) {
                var rulesObj = {};
                for (var i = 0; i < validationFields.length; i++) {
                    var validationField = validationFields[i];
                    var fieldName = validationField.FieldName;
                    rulesObj[fieldName] = createRulesForField(validationField);
                }
 
                return rulesObj;
            }

It is on this function where it produces the error.
validationFields comes as undefined.
0
Atanas Korchev
Telerik team
answered on 04 Jul 2011, 12:23 PM
Hi Nohinn,

 This could be related to the dynamic class generation. We cannot be sure though. I suggest you check if your dynamic classes can be validated in a regular Html.Form(). 

Regards,

Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 04 Jul 2011, 12:49 PM
I was debugging right now the javascript file, I don't know if this is the normal behavior but in this line:
var theForm = $("#" + validationContext.FormId);
in this validationContext variable I can only see my dynamic grid columns, so no FormId var neither Fields var which is trying to use after this line and ends up producing the error.
0
Atanas Korchev
Telerik team
answered on 04 Jul 2011, 02:06 PM
Hello Nohinn,

 No, this is not the normal behavior. However that information is generated by ASP.NET MVC. I suggest you try enabling validation for your object in a vanilla Html.Form without involving the grid. If it does not work there it won't work with the Telerik Grid either.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nohinn
Top achievements
Rank 1
answered on 04 Jul 2011, 08:08 PM
Everything is working now hehe.

I was calling the Render of the grid after writing the initialization script and that's why I was not getting any Fields nor FormId property in that variable.
Now I have a reflection grid + codedom generated classes and editable too :D
Thanks for all your help devs :)
Tags
Grid
Asked by
Nohinn
Top achievements
Rank 1
Answers by
Demon
Top achievements
Rank 1
Nohinn
Top achievements
Rank 1
Atanas Korchev
Telerik team
Rosen
Telerik team
Share this question
or