This question is locked. New answers and comments are not allowed.
Andy McShane
Top achievements
Rank 1
Andy McShane
asked on 05 Feb 2010, 01:33 PM
Hi all, I have been playing with this for hours now and getting nowhere fast. I am trying to use the Grid control using the following code,
This is in my master page in the header
This is in my master page after the footer
This is what I have on my view
My controller looks like this
Now I can get the grid to display ok, it sorts ok and pages ok, I also get the filter icon and the filter box appears but as soon as I select any filter criteria and click filter I get a javascript error 'Syntax error' in telerik.grid.min.js.
This driving me nuts! Can anyone shed any light on this, I am desperate!
This is in my master page in the header
| <% |
| Html.Telerik().StyleSheetRegistrar() |
| .DefaultGroup(group => group.Add("telerik.common.css") |
| .Add("telerik.vista.css")) |
| .Render(); |
| %> |
This is in my master page after the footer
| <%= Html.Telerik().ScriptRegistrar() %> |
This is what I have on my view
| <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> |
| Index |
| </asp:Content> |
| <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> |
| <h2>List All Service Users</h2> |
| <!--TESTING CODE--> |
| <%= Html.Telerik().Grid(Model) |
| .Name("Grid") |
| .Columns(columns => |
| { |
| columns.Add(o => o.ServiceUserId); |
| columns.Add(o => o.UserMembershipId); |
| columns.Add(o => o.CustomerId); |
| columns.Add(o => o.KnownName); |
| columns.Add(o => o.ServiceUserUserName); |
| columns.Add(o => o.ServiceUserFirstName); |
| columns.Add(o => o.ServiceUserSurname); |
| columns.Add(o => o.ServiceUserEmail); |
| columns.Add(o => o.DateOfBirth).Format("{0:MM/dd/yyyy}"); |
| }) |
| .Ajax(ajax => ajax.Action("Index", "ServiceUser")) |
| .Pageable() |
| .Sortable() |
| .Filterable() %> |
| </asp:Content> |
My controller looks like this
| // |
| // GET: /ServiceUser/ |
| [GridAction] |
| public ActionResult Index() |
| { |
| return View(_serviceUserService.GetServiceUsersAll()); |
| } |
Now I can get the grid to display ok, it sorts ok and pages ok, I also get the filter icon and the filter box appears but as soon as I select any filter criteria and click filter I get a javascript error 'Syntax error' in telerik.grid.min.js.
This driving me nuts! Can anyone shed any light on this, I am desperate!
9 Answers, 1 is accepted
0
Hello Andy McShane,
Does filtering fail for every column? Have you tried running the sample ASP.NET MVC Application? Does the filtering run as expected there?
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Does filtering fail for every column? Have you tried running the sample ASP.NET MVC Application? Does the filtering run as expected there?
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Andy McShane
Top achievements
Rank 1
answered on 05 Feb 2010, 02:53 PM
Hi, I have not run the examples locally as yet, I will try that now. I thought I had sorting working but I get this error on both sorting and filtering and on every column.
0
Hello Andy McShane,
This is very strange. Which browser are you using? Do you have any other JavaScript included in your page? What is the exact error message you are seeing - could you attach a screenshot?
Any additional information will help identify the problem.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
This is very strange. Which browser are you using? Do you have any other JavaScript included in your page? What is the exact error message you are seeing - could you attach a screenshot?
Any additional information will help identify the problem.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Andy McShane
Top achievements
Rank 1
answered on 05 Feb 2010, 03:39 PM
I have now run the examples locally and do not get this error so I am assuming that it must be something to do with my configuration. The actual error I am getting, according to Firebug is as follows;
Not that this is really much help I suppose.
I have attached a screen shot. I have no other Javascript files within my project.
| (function(e){var b=e.telerik;var f=/"\\\/Date\((.*?)\)\\\/"/g;var d=/d{1,4}|M{1,4}|yy(?:yy)?|([Hhmstf])\1*|"[^"]*"|'[^']*'/g;e.extend(b,{grid:function(k,l){this.element=k;this.sorted=[];e.extend(this,l);e(".t-pager .t-state-disabled",this.element).live("click",b.preventDefault);e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave);e(".t-pager input[type=text]",this.element).live("keydown",b.delegate(this,this.pagerKeyDown));if(this.sort){e(".t-header .t-link",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave)}for(var j=0;j<this.plugins.length;j++){b[this.plugins[j]].initialize(this)}var h=this.$headerWrap=e(".t-grid-header-wrap",this.element);var m=e(".t-grid-content",this.element).bind("scroll",function(){h.scrollLeft(this.scrollLeft)});this.$tbody=e(".t-grid-content table tbody",this.element);if(!this.$tbody.length){this.$tbody=e("table tbody",this.element)}e(".t-refresh",this.element).live("click",b.delegate(this,this.refreshClick));if(this.onError){e(k).bind("errorGrid",this.onError)}if(this.onDataBinding){e(k).bind("dataBindingGrid",this.onDataBinding)}if(this.onRowDataBound){e(k).bind("rowDataBoundGrid",this.onRowDataBound)}if(this.isAjax()){e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("click",b.delegate(this,this.pagerClick));if(this.sort){e(".t-header > .t-link",this.element).live("click",b.delegate(this,this.headerClick))}}if(this.onLoad){e(this.element).bind("loadGrid",this,this.onLoad).trigger("loadGrid")}},formatString:function(){var h=arguments[0];for(var o=0,p=arguments.length-1;o<p;o++){var j=new RegExp("\\{"+o+"(:([^\\}]+))?\\}","gm");var n=arguments[o+1];var m=this.formatters[g(n)];if(m){var k=j.exec(h);n=m(n,k[2])}hh=h.replace(j,n)}return h},formatters:{date:c},cultureInfo:{longDate:"dddd, MMMM dd, yyyy",shortDate:"M/d/yyyy",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",generalDateShortTime:"M/d/yyyy h:mm tt",generalDateTime:"M/d/yyyy h:mm:ss tt",sortableDateTime:"yyyy'-'MM'-'ddTHH':'mm':'ss",universalSortableDateTime:"yyyy'-'MM'-'dd HH':'mm':'ss'Z'",monthYear:"MMMM, yyyy",monthDay:"MMMM dd",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbrDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],abbrMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],am:"AM",pm:"PM",dateSeparator:"/",timeSeparator:":"}});function g(h){if(h instanceof Date){return"date"}return"object"}function a(h){if(h<10){return"0"+h}return h}function c(t,v){var k=b.cultureInfo;var p={d:k.shortDate,D:k.longDate,F:k.fullDateTime,g:k.generalDateShortTime,G:k.generalDateTime,m:k.monthDay,M:k.monthDay,s:k.sortableDateTime,u:k.universalSortableDateTime,y:k.monthYear,Y:k.monthYear};var q=t.getDate();var i=t.getDay();var n=t.getMonth();var j=t.getFullYear();var x=t.getHours();var w=t.getMinutes();var u=t.getSeconds();var r=t.getMilliseconds();var o={d:q,dd:a(q),ddd:k.abbrDays[i],dddd:k.days[i],M:n+1,MM:a(n+1),MMM:k.abbrMonths[n],MMMM:k.months[n],yy:a(j%100),yyyy:j,h:x%12||12,hh:a(x%12||12),H:x,HH:a(x),m:w,mm:a(w),s:u,ss:a(u),f:Math.floor(r/100),ff:Math.floor(r/10),fff:r,tt:x<12?k.am:k.pm};vv=v||"G";v=p[v]?p[v]:v;return v.replace(d,function(h){return h in o?o[h]:h.slice(1,h.length-1)})}e.extend(b.grid.prototype,{headerClick:function(i,h){i.preventDefault();this.sort(h.parentNode.cellIndex)},refreshClick:function(i,h){i.preventDefault();if(e(h).is(".t-loading")){return}if(this.isAjax()){this.ajaxRequest(true)}else{location.reload()}},sort:function(h){thisthis.orderBy=this.sortExpr(h);this.ajaxRequest()},sortExpr:function(h){var o=this.columns[h];var k="asc";if(o.sortDirection=="asc"){k="desc"}else{if(o.sortDirection=="desc"){k=null}}o.sortDirection=k;var n=e.inArray(o,this.sorted);if(this.sortMode=="single"&&n<0){for(var m=0;m<this.sorted.length;m++){this.sorted[m].sortDirection=null}this.sorted=[]}if(n<0&&k){this.sorted.push(o)}if(!k){this.sorted.splice(n,1)}var l=[];for(var m=0,j=this.sorted.length;m<j;m++){l.push(this.sorted[m].name+"-"+this.sorted[m].sortDirection)}return l.join("~")},pagerKeyDown:function(j,i){if(j.keyCode==13){var h=this.sanitizePage(e(i).val());if(h!=this.currentPage){this.pageTo(h)}else{e(i).val(h)}}},isAjax:function(){return this.ajaxUrl||this.onDataBinding},pagerClick:function(l,k){l.preventDefault();var h=this.currentPage;var m=e(k).find(".t-icon");if(m.hasClass("t-arrow-next")){h++}else{if(m.hasClass("t-arrow-last")){h=this.totalPages()}else{if(m.hasClass("t-arrow-prev")){h--}else{if(m.hasClass("t-arrow-first")){h=1}else{var j=e(k).text();if(j=="..."){var i=e(k).parent().children().index(k);if(i==0){h=parseInt(e(k).next().text(),10)-1}else{h=parseInt(e(k).prev().text(),10)+1}}else{h=parseInt(j,10)}}}}}this.pageTo(h)},pageTo:function(h){this.currentPage=h;this.ajaxRequest()},ajaxRequest:function(l){if(b.trigger(this.element,"dataBindingGrid",{page:this.currentPage,sortedColumns:this.sorted,filteredColumns:e.grep(this.columns,function(p){return p.filters})})){return}if(!this.ajaxUrl){return}var k={};k[this.queryString.page]=this.currentPage;k[this.queryString.size]=this.pageSize;k[this.queryString.orderBy]=this.orderBy||"";k[this.queryString.filter]=(this.filterExpression||"").replace(/\"/g,'\\"');var m=e(".t-status .t-icon",this.element);var n=function(){m.addClass("t-loading")};if(l){n()}var j=setTimeout(n,100);var h={type:"POST",url:this.ajaxUrl,dataType:"text",dataFilter:function(q,p){return q.replace(f,"new Date($1)")},error:e.proxy(function(q,p){if(b.ajaxError(this.element,"error.Grid",q,p)){return}if(p=="parsererror"){alert("Error! The requested URL did not return JSON.")}},this),complete:function(){clearTimeout(j);m.removeClass("t-loading")},success:e.proxy(function(p){p=eval("("+p+")");pp=p.d||p;this.total=p.total||p.Total||0;this.dataBind(p.data||p.Data)},this)};if(this.ws){var o=[];for(var i in k){o.push(b.formatString('"{0}":"{1}"',i,k[i]))}h.data="{"+o.join(",")+"}";h.contentType="application/json; charset=utf-8"}else{h.data=k}e.ajax(h)},createMapping:function(j){var h=new b.stringBuilder();h.cat("var result = data.").cat(j.name).cat(";");if(j.format||j.type=="Date"){var i=j.format||"{0:G}";ii=i.replace(/"/ig,'\\"');h.cat('result = $.telerik.formatString("').cat(i).cat('", result);')}h.cat("return result;");return new Function("data",h.string())},createColumnMappings:function(n){for(var h in n){for(var m=0,k=this.columns.length;m<k;m++){var j=this.columns[m];if(!j.name){continue}if(j.name.indexOf(h)>-1){j.mapping=this.createMapping(j)}}}},bindTo:function(p){this.$tbody.find("tr.t-no-data").remove();this.createColumnMappings(p[0]);var k=this.$tbody[0].rows;var n=k.length;var o=Math.min(this.pageSize,p.length);if(this.pageSize==0){o=p.length}if(n<o){var u=new b.stringBuilder();for(var m=n;m<o;m++){if(m%2==1){u.cat('<tr class="t-alt">')}else{u.cat("<tr>")}for(var j=0,q=this.columns.length;j<q;j++){u.cat("<td").cat(this.columns[j].attr).cat("/>")}u.cat("</tr>")}e(u.string()).appendTo(this.$tbody)}for(var m=0;m<o;m++){var r=k[m];for(var h=0,t=this.columns.length;h<t;h++){var s=this.columns[h].mapping;if(s){r.cells[h].innerHTML=s(p[m])}}if(this.onRowDataBound){b.trigger(this.element,"rowDataBoundGrid",{row:r,dataItem:p[m]})}}for(;m<n;m++){e(k[k.length-1]).remove()}},updatePager:function(){var i=this.totalPages(this.total);var h=this.currentPage;var j=e(".t-pager",this.element);j.find(".t-arrow-next").parent().add(j.find(".t-arrow-last").parent()).toggleClass("t-state-disabled",h>=i).removeClass("t-state-hover");j.find(".t-arrow-prev").parent().add(j.find(".t-arrow-first").parent()).toggleClass("t-state-disabled",h==1).removeClass("t-state-hover");j.find(".t-page-i-of-n").each(function(){this.innerHTML=b.formatString('Page <input type="text" value="{0}" /> of {1}',h,i)});j.find(".t-numeric").each(e.proxy(function(l,k){this.numericPager(k,h,i)},this));e(".t-status-text",this.element).text(b.formatString("Displaying items {0} - {1} of {2}",this.firstItemInPage(),this.lastItemInPage(),this.total))},numericPager:function(o,m,p){var n=10;var h=1;if(m>n){var k=(m%n);h=(k==0)?(m-n)+1:(m-k)+1}var l=(h+n)-1;l=Math.min(l,p);var i=new b.stringBuilder();if(h>1){i.cat('<a class="t-link">...</a>')}for(var j=h;j<=l;j++){if(j==m){i.cat('<span class="t-state-active">').cat(j).cat("</span>")}else{i.cat('<a class="t-link">').cat(j).cat("</a>")}}if(l<p){i.cat('<a class="t-link">...</a>')}o.innerHTML=i.string()},updateSorting:function(){e(".t-header",this.element).each(e.proxy(function(l,m){var j=this.columns[l].sortDirection;var k=e(m).children(".t-link");var h=k.children(".t-icon");if(!j){h.hide()}else{if(h.length==0){h=e('<span class="t-icon"/>').appendTo(k)}h.toggleClass("t-arrow-up",j=="asc").toggleClass("t-arrow-down",j=="desc").show()}},this))},sanitizePage:function(h){var i=parseInt(h,10);if(isNaN(i)||i<1){return 1}return Math.min(i,this.totalPages())},totalPages:function(){return Math.ceil(this.total/this.pageSize)},firstItemInPage:function(){return this.total>0?(this.currentPage-1)*this.pageSize+1:0},lastItemInPage:function(){return Math.min(this.currentPage*this.pageSize,this.total)},dataBind:function(h){this.bindTo(h);this.updatePager();this.updateSorting()},rebind:function(h){this.sorted=[];this.currentPage=1;e.each(this.columns,function(){this.sortDirection=null;this.filters=[]});for(var j in h){var k=new RegExp(b.formatString("({0})=([^&]*)",j),"g");if(k.test(this.ajaxUrl)){thisthis.ajaxUrl=this.ajaxUrl.replace(k,"$1="+h[j])}else{var i=new b.stringBuilder();i.cat(this.ajaxUrl);if(this.ajaxUrl.indexOf("?")<0){i.cat("?")}this.ajaxUrl=i.cat(j).cat("=").cat(h[j]).string()}}this.ajaxRequest()}});e.fn.tGrid=function(h){h=e.extend({},e.fn.tGrid.defaults,h);return this.each(function(){h=e.meta?e.extend({},h,e(this).data()):h;if(!e(this).data("tGrid")){var i=new b.grid(this,h);e(this).data("tGrid",i);if(i.$tbody.find("tr.t-no-data").length){i.ajaxRequest()}}})};e.fn.tGrid.defaults={columns:[],plugins:[],currentPage:1,pageSize:10,queryString:{page:"page",size:"size",orderBy:"orderBy",filter:"filter"}}})(jQuery); |
Not that this is really much help I suppose.
I have attached a screen shot. I have no other Javascript files within my project.
0
Hello Andy McShane,
I suspect for some reason some JavaScript file may have failed to load. You can check using firebug in the NET tab. The grid requires the following files to be included - telerik.common.js telerik.grid.js and telerik.grid.filtering.js. If combining is enabled there should be a single request to asset.axd though.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
I suspect for some reason some JavaScript file may have failed to load. You can check using firebug in the NET tab. The grid requires the following files to be included - telerik.common.js telerik.grid.js and telerik.grid.filtering.js. If combining is enabled there should be a single request to asset.axd though.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Andy McShane
Top achievements
Rank 1
answered on 10 Feb 2010, 11:05 AM
Hi, I can confirm that all of the required scripts are loading and whilst debugging in Visual Studio I get the following syntax error within telerik.grid.min.js (I have marked the bit of script that visual studio highlights below)
'(function(e){var b=e.telerik;var f=/"\\\/Date\((.*?)\)\\\/"/g;var d=/d{1,4}|M{1,4}|yy(?:yy)?|([Hhmstf])\1*|"[^"]*"|'[^']*'/g;e.extend(b,{grid:function(k,l){this.element=k;this.sorted=[];e.extend(this,l);e(".t-pager .t-state-disabled",this.element).live("click",b.preventDefault);e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave);e(".t-pager input[type=text]",this.element).live("keydown",b.delegate(this,this.pagerKeyDown));if(this.sort){e(".t-header .t-link",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave)}for(var j=0;j<this.plugins.length;j++){b[this.plugins[j]].initialize(this)}var h=this.$headerWrap=e(".t-grid-header-wrap",this.element);var m=e(".t-grid-content",this.element).bind("scroll",function(){h.scrollLeft(this.scrollLeft)});this.$tbody=e(".t-grid-content table tbody",this.element);if(!this.$tbody.length){this.$tbody=e("table tbody",this.element)}e(".t-refresh",this.element).live("click",b.delegate(this,this.refreshClick));if(this.onError){e(k).bind("errorGrid",this.onError)}if(this.onDataBinding){e(k).bind("dataBindingGrid",this.onDataBinding)}if(this.onRowDataBound){e(k).bind("rowDataBoundGrid",this.onRowDataBound)}if(this.isAjax()){e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("click",b.delegate(this,this.pagerClick));if(this.sort){e(".t-header > .t-link",this.element).live("click",b.delegate(this,this.headerClick))}}if(this.onLoad){e(this.element).bind("loadGrid",this,this.onLoad).trigger("loadGrid")}},formatString:function(){var h=arguments[0];for(var o=0,p=arguments.length-1;o<p;o++){var j=new RegExp("\\{"+o+"(:([^\\}]+))?\\}","gm");var n=arguments[o+1];var m=this.formatters[g(n)];if(m){var k=j.exec(h);n=m(n,k[2])}h=h.replace(j,n)}return h},formatters:{date:c},cultureInfo:{longDate:"dddd, MMMM dd, yyyy",shortDate:"M/d/yyyy",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",generalDateShortTime:"M/d/yyyy h:mm tt",generalDateTime:"M/d/yyyy h:mm:ss tt",sortableDateTime:"yyyy'-'MM'-'ddTHH':'mm':'ss",universalSortableDateTime:"yyyy'-'MM'-'dd HH':'mm':'ss'Z'",monthYear:"MMMM, yyyy",monthDay:"MMMM dd",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbrDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],abbrMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],am:"AM",pm:"PM",dateSeparator:"/",timeSeparator:":"}});function g(h){if(h instanceof Date){return"date"}return"object"}function a(h){if(h<10){return"0"+h}return h}function c(t,v){var k=b.cultureInfo;var p={d:k.shortDate,D:k.longDate,F:k.fullDateTime,g:k.generalDateShortTime,G:k.generalDateTime,m:k.monthDay,M:k.monthDay,s:k.sortableDateTime,u:k.universalSortableDateTime,y:k.monthYear,Y:k.monthYear};var q=t.getDate();var i=t.getDay();var n=t.getMonth();var j=t.getFullYear();var x=t.getHours();var w=t.getMinutes();var u=t.getSeconds();var r=t.getMilliseconds();var o={d:q,dd:a(q),ddd:k.abbrDays[i],dddd:k.days[i],M:n+1,MM:a(n+1),MMM:k.abbrMonths[n],MMMM:k.months[n],yy:a(j%100),yyyy:j,h:x%12||12,hh:a(x%12||12),H:x,HH:a(x),m:w,mm:a(w),s:u,ss:a(u),f:Math.floor(r/100),ff:Math.floor(r/10),fff:r,tt:x<12?k.am:k.pm};v=v||"G";v=p[v]?p[v]:v;return v.replace(d,function(h){return h in o?o[h]:h.slice(1,h.length-1)})}e.extend(b.grid.prototype,{headerClick:function(i,h){i.preventDefault();this.sort(h.parentNode.cellIndex)},refreshClick:function(i,h){i.preventDefault();if(e(h).is(".t-loading")){return}if(this.isAjax()){this.ajaxRequest(true)}else{location.reload()}},sort:function(h){this.orderBy=this.sortExpr(h);this.ajaxRequest()},sortExpr:function(h){var o=this.columns[h];var k="asc";if(o.sortDirection=="asc"){k="desc"}else{if(o.sortDirection=="desc"){k=null}}o.sortDirection=k;var n=e.inArray(o,this.sorted);if(this.sortMode=="single"&&n<0){for(var m=0;m<this.sorted.length;m++){this.sorted[m].sortDirection=null}this.sorted=[]}if(n<0&&k){this.sorted.push(o)}if(!k){this.sorted.splice(n,1)}var l=[];for(var m=0,j=this.sorted.length;m<j;m++){l.push(this.sorted[m].name+"-"+this.sorted[m].sortDirection)}return l.join("~")},pagerKeyDown:function(j,i){if(j.keyCode==13){var h=this.sanitizePage(e(i).val());if(h!=this.currentPage){this.pageTo(h)}else{e(i).val(h)}}},isAjax:function(){return this.ajaxUrl||this.onDataBinding},pagerClick:function(l,k){l.preventDefault();var h=this.currentPage;var m=e(k).find(".t-icon");if(m.hasClass("t-arrow-next")){h++}else{if(m.hasClass("t-arrow-last")){h=this.totalPages()}else{if(m.hasClass("t-arrow-prev")){h--}else{if(m.hasClass("t-arrow-first")){h=1}else{var j=e(k).text();if(j=="..."){var i=e(k).parent().children().index(k);if(i==0){h=parseInt(e(k).next().text(),10)-1}else{h=parseInt(e(k).prev().text(),10)+1}}else{h=parseInt(j,10)}}}}}this.pageTo(h)},pageTo:function(h){this.currentPage=h;this.ajaxRequest()},ajaxRequest:function(l){if(b.trigger(this.element,"dataBindingGrid",{page:this.currentPage,sortedColumns:this.sorted,filteredColumns:e.grep(this.columns,function(p){return p.filters})})){return}if(!this.ajaxUrl){return}var k={};k[this.queryString.page]=this.currentPage;k[this.queryString.size]=this.pageSize;k[this.queryString.orderBy]=this.orderBy||"";k[this.queryString.filter]=(this.filterExpression||"").replace(/\"/g,'\\"');var m=e(".t-status .t-icon",this.element);var n=function(){m.addClass("t-loading")};if(l){n()}var j=setTimeout(n,100);var h={type:"POST",url:this.ajaxUrl,dataType:"text",dataFilter:function(q,p){return q.replace(f,"new Date($1)")},error:e.proxy(function(q,p){if(b.ajaxError(this.element,"error.Grid",q,p)){return}if(p=="parsererror"){alert("Error! The requested URL did not return JSON.")}},this),complete:function(){clearTimeout(j);m.removeClass("t-loading")},success:e.proxy(function(p){
p=eval("("+p+")"); -- VISUAL STUDIO HIGHLIGHTS THIS CODE AS A SYNTAX ERROR???
p=p.d||p;this.total=p.total||p.Total||0;this.dataBind(p.data||p.Data)},this)};if(this.ws){var o=[];for(var i in k){o.push(b.formatString('"{0}":"{1}"',i,k[i]))}h.data="{"+o.join(",")+"}";h.contentType="application/json; charset=utf-8"}else{h.data=k}e.ajax(h)},createMapping:function(j){var h=new b.stringBuilder();h.cat("var result = data.").cat(j.name).cat(";");if(j.format||j.type=="Date"){var i=j.format||"{0:G}";i=i.replace(/"/ig,'\\"');h.cat('result = $.telerik.formatString("').cat(i).cat('", result);')}h.cat("return result;");return new Function("data",h.string())},createColumnMappings:function(n){for(var h in n){for(var m=0,k=this.columns.length;m<k;m++){var j=this.columns[m];if(!j.name){continue}if(j.name.indexOf(h)>-1){j.mapping=this.createMapping(j)}}}},bindTo:function(p){this.$tbody.find("tr.t-no-data").remove();this.createColumnMappings(p[0]);var k=this.$tbody[0].rows;var n=k.length;var o=Math.min(this.pageSize,p.length);if(this.pageSize==0){o=p.length}if(n<o){var u=new b.stringBuilder();for(var m=n;m<o;m++){if(m%2==1){u.cat('<tr class="t-alt">')}else{u.cat("<tr>")}for(var j=0,q=this.columns.length;j<q;j++){u.cat("<td").cat(this.columns[j].attr).cat("/>")}u.cat("</tr>")}e(u.string()).appendTo(this.$tbody)}for(var m=0;m<o;m++){var r=k[m];for(var h=0,t=this.columns.length;h<t;h++){var s=this.columns[h].mapping;if(s){r.cells[h].innerHTML=s(p[m])}}if(this.onRowDataBound){b.trigger(this.element,"rowDataBoundGrid",{row:r,dataItem:p[m]})}}for(;m<n;m++){e(k[k.length-1]).remove()}},updatePager:function(){var i=this.totalPages(this.total);var h=this.currentPage;var j=e(".t-pager",this.element);j.find(".t-arrow-next").parent().add(j.find(".t-arrow-last").parent()).toggleClass("t-state-disabled",h>=i).removeClass("t-state-hover");j.find(".t-arrow-prev").parent().add(j.find(".t-arrow-first").parent()).toggleClass("t-state-disabled",h==1).removeClass("t-state-hover");j.find(".t-page-i-of-n").each(function(){this.innerHTML=b.formatString('Page <input type="text" value="{0}" /> of {1}',h,i)});j.find(".t-numeric").each(e.proxy(function(l,k){this.numericPager(k,h,i)},this));e(".t-status-text",this.element).text(b.formatString("Displaying items {0} - {1} of {2}",this.firstItemInPage(),this.lastItemInPage(),this.total))},numericPager:function(o,m,p){var n=10;var h=1;if(m>n){var k=(m%n);h=(k==0)?(m-n)+1:(m-k)+1}var l=(h+n)-1;l=Math.min(l,p);var i=new b.stringBuilder();if(h>1){i.cat('<a class="t-link">...</a>')}for(var j=h;j<=l;j++){if(j==m){i.cat('<span class="t-state-active">').cat(j).cat("</span>")}else{i.cat('<a class="t-link">').cat(j).cat("</a>")}}if(l<p){i.cat('<a class="t-link">...</a>')}o.innerHTML=i.string()},updateSorting:function(){e(".t-header",this.element).each(e.proxy(function(l,m){var j=this.columns[l].sortDirection;var k=e(m).children(".t-link");var h=k.children(".t-icon");if(!j){h.hide()}else{if(h.length==0){h=e('<span class="t-icon"/>').appendTo(k)}h.toggleClass("t-arrow-up",j=="asc").toggleClass("t-arrow-down",j=="desc").show()}},this))},sanitizePage:function(h){var i=parseInt(h,10);if(isNaN(i)||i<1){return 1}return Math.min(i,this.totalPages())},totalPages:function(){return Math.ceil(this.total/this.pageSize)},firstItemInPage:function(){return this.total>0?(this.currentPage-1)*this.pageSize+1:0},lastItemInPage:function(){return Math.min(this.currentPage*this.pageSize,this.total)},dataBind:function(h){this.bindTo(h);this.updatePager();this.updateSorting()},rebind:function(h){this.sorted=[];this.currentPage=1;e.each(this.columns,function(){this.sortDirection=null;this.filters=[]});for(var j in h){var k=new RegExp(b.formatString("({0})=([^&]*)",j),"g");if(k.test(this.ajaxUrl)){this.ajaxUrl=this.ajaxUrl.replace(k,"$1="+h[j])}else{var i=new b.stringBuilder();i.cat(this.ajaxUrl);if(this.ajaxUrl.indexOf("?")<0){i.cat("?")}this.ajaxUrl=i.cat(j).cat("=").cat(h[j]).string()}}this.ajaxRequest()}});e.fn.tGrid=function(h){h=e.extend({},e.fn.tGrid.defaults,h);return this.each(function(){h=e.meta?e.extend({},h,e(this).data()):h;if(!e(this).data("tGrid")){var i=new b.grid(this,h);e(this).data("tGrid",i);if(i.$tbody.find("tr.t-no-data").length){i.ajaxRequest()}}})};e.fn.tGrid.defaults={columns:[],plugins:[],currentPage:1,pageSize:10,queryString:{page:"page",size:"size",orderBy:"orderBy",filter:"filter"}}})(jQuery);
So I am unsure what to look at next? Is there an uncompressed version of the script that I can use to try and debug?
'(function(e){var b=e.telerik;var f=/"\\\/Date\((.*?)\)\\\/"/g;var d=/d{1,4}|M{1,4}|yy(?:yy)?|([Hhmstf])\1*|"[^"]*"|'[^']*'/g;e.extend(b,{grid:function(k,l){this.element=k;this.sorted=[];e.extend(this,l);e(".t-pager .t-state-disabled",this.element).live("click",b.preventDefault);e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave);e(".t-pager input[type=text]",this.element).live("keydown",b.delegate(this,this.pagerKeyDown));if(this.sort){e(".t-header .t-link",this.element).live("mouseenter",b.hover).live("mouseleave",b.leave)}for(var j=0;j<this.plugins.length;j++){b[this.plugins[j]].initialize(this)}var h=this.$headerWrap=e(".t-grid-header-wrap",this.element);var m=e(".t-grid-content",this.element).bind("scroll",function(){h.scrollLeft(this.scrollLeft)});this.$tbody=e(".t-grid-content table tbody",this.element);if(!this.$tbody.length){this.$tbody=e("table tbody",this.element)}e(".t-refresh",this.element).live("click",b.delegate(this,this.refreshClick));if(this.onError){e(k).bind("errorGrid",this.onError)}if(this.onDataBinding){e(k).bind("dataBindingGrid",this.onDataBinding)}if(this.onRowDataBound){e(k).bind("rowDataBoundGrid",this.onRowDataBound)}if(this.isAjax()){e(".t-pager .t-link:not(.t-state-disabled)",this.element).live("click",b.delegate(this,this.pagerClick));if(this.sort){e(".t-header > .t-link",this.element).live("click",b.delegate(this,this.headerClick))}}if(this.onLoad){e(this.element).bind("loadGrid",this,this.onLoad).trigger("loadGrid")}},formatString:function(){var h=arguments[0];for(var o=0,p=arguments.length-1;o<p;o++){var j=new RegExp("\\{"+o+"(:([^\\}]+))?\\}","gm");var n=arguments[o+1];var m=this.formatters[g(n)];if(m){var k=j.exec(h);n=m(n,k[2])}h=h.replace(j,n)}return h},formatters:{date:c},cultureInfo:{longDate:"dddd, MMMM dd, yyyy",shortDate:"M/d/yyyy",fullDateTime:"dddd, MMMM dd, yyyy h:mm:ss tt",generalDateShortTime:"M/d/yyyy h:mm tt",generalDateTime:"M/d/yyyy h:mm:ss tt",sortableDateTime:"yyyy'-'MM'-'ddTHH':'mm':'ss",universalSortableDateTime:"yyyy'-'MM'-'dd HH':'mm':'ss'Z'",monthYear:"MMMM, yyyy",monthDay:"MMMM dd",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbrDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],abbrMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],am:"AM",pm:"PM",dateSeparator:"/",timeSeparator:":"}});function g(h){if(h instanceof Date){return"date"}return"object"}function a(h){if(h<10){return"0"+h}return h}function c(t,v){var k=b.cultureInfo;var p={d:k.shortDate,D:k.longDate,F:k.fullDateTime,g:k.generalDateShortTime,G:k.generalDateTime,m:k.monthDay,M:k.monthDay,s:k.sortableDateTime,u:k.universalSortableDateTime,y:k.monthYear,Y:k.monthYear};var q=t.getDate();var i=t.getDay();var n=t.getMonth();var j=t.getFullYear();var x=t.getHours();var w=t.getMinutes();var u=t.getSeconds();var r=t.getMilliseconds();var o={d:q,dd:a(q),ddd:k.abbrDays[i],dddd:k.days[i],M:n+1,MM:a(n+1),MMM:k.abbrMonths[n],MMMM:k.months[n],yy:a(j%100),yyyy:j,h:x%12||12,hh:a(x%12||12),H:x,HH:a(x),m:w,mm:a(w),s:u,ss:a(u),f:Math.floor(r/100),ff:Math.floor(r/10),fff:r,tt:x<12?k.am:k.pm};v=v||"G";v=p[v]?p[v]:v;return v.replace(d,function(h){return h in o?o[h]:h.slice(1,h.length-1)})}e.extend(b.grid.prototype,{headerClick:function(i,h){i.preventDefault();this.sort(h.parentNode.cellIndex)},refreshClick:function(i,h){i.preventDefault();if(e(h).is(".t-loading")){return}if(this.isAjax()){this.ajaxRequest(true)}else{location.reload()}},sort:function(h){this.orderBy=this.sortExpr(h);this.ajaxRequest()},sortExpr:function(h){var o=this.columns[h];var k="asc";if(o.sortDirection=="asc"){k="desc"}else{if(o.sortDirection=="desc"){k=null}}o.sortDirection=k;var n=e.inArray(o,this.sorted);if(this.sortMode=="single"&&n<0){for(var m=0;m<this.sorted.length;m++){this.sorted[m].sortDirection=null}this.sorted=[]}if(n<0&&k){this.sorted.push(o)}if(!k){this.sorted.splice(n,1)}var l=[];for(var m=0,j=this.sorted.length;m<j;m++){l.push(this.sorted[m].name+"-"+this.sorted[m].sortDirection)}return l.join("~")},pagerKeyDown:function(j,i){if(j.keyCode==13){var h=this.sanitizePage(e(i).val());if(h!=this.currentPage){this.pageTo(h)}else{e(i).val(h)}}},isAjax:function(){return this.ajaxUrl||this.onDataBinding},pagerClick:function(l,k){l.preventDefault();var h=this.currentPage;var m=e(k).find(".t-icon");if(m.hasClass("t-arrow-next")){h++}else{if(m.hasClass("t-arrow-last")){h=this.totalPages()}else{if(m.hasClass("t-arrow-prev")){h--}else{if(m.hasClass("t-arrow-first")){h=1}else{var j=e(k).text();if(j=="..."){var i=e(k).parent().children().index(k);if(i==0){h=parseInt(e(k).next().text(),10)-1}else{h=parseInt(e(k).prev().text(),10)+1}}else{h=parseInt(j,10)}}}}}this.pageTo(h)},pageTo:function(h){this.currentPage=h;this.ajaxRequest()},ajaxRequest:function(l){if(b.trigger(this.element,"dataBindingGrid",{page:this.currentPage,sortedColumns:this.sorted,filteredColumns:e.grep(this.columns,function(p){return p.filters})})){return}if(!this.ajaxUrl){return}var k={};k[this.queryString.page]=this.currentPage;k[this.queryString.size]=this.pageSize;k[this.queryString.orderBy]=this.orderBy||"";k[this.queryString.filter]=(this.filterExpression||"").replace(/\"/g,'\\"');var m=e(".t-status .t-icon",this.element);var n=function(){m.addClass("t-loading")};if(l){n()}var j=setTimeout(n,100);var h={type:"POST",url:this.ajaxUrl,dataType:"text",dataFilter:function(q,p){return q.replace(f,"new Date($1)")},error:e.proxy(function(q,p){if(b.ajaxError(this.element,"error.Grid",q,p)){return}if(p=="parsererror"){alert("Error! The requested URL did not return JSON.")}},this),complete:function(){clearTimeout(j);m.removeClass("t-loading")},success:e.proxy(function(p){
p=eval("("+p+")"); -- VISUAL STUDIO HIGHLIGHTS THIS CODE AS A SYNTAX ERROR???
p=p.d||p;this.total=p.total||p.Total||0;this.dataBind(p.data||p.Data)},this)};if(this.ws){var o=[];for(var i in k){o.push(b.formatString('"{0}":"{1}"',i,k[i]))}h.data="{"+o.join(",")+"}";h.contentType="application/json; charset=utf-8"}else{h.data=k}e.ajax(h)},createMapping:function(j){var h=new b.stringBuilder();h.cat("var result = data.").cat(j.name).cat(";");if(j.format||j.type=="Date"){var i=j.format||"{0:G}";i=i.replace(/"/ig,'\\"');h.cat('result = $.telerik.formatString("').cat(i).cat('", result);')}h.cat("return result;");return new Function("data",h.string())},createColumnMappings:function(n){for(var h in n){for(var m=0,k=this.columns.length;m<k;m++){var j=this.columns[m];if(!j.name){continue}if(j.name.indexOf(h)>-1){j.mapping=this.createMapping(j)}}}},bindTo:function(p){this.$tbody.find("tr.t-no-data").remove();this.createColumnMappings(p[0]);var k=this.$tbody[0].rows;var n=k.length;var o=Math.min(this.pageSize,p.length);if(this.pageSize==0){o=p.length}if(n<o){var u=new b.stringBuilder();for(var m=n;m<o;m++){if(m%2==1){u.cat('<tr class="t-alt">')}else{u.cat("<tr>")}for(var j=0,q=this.columns.length;j<q;j++){u.cat("<td").cat(this.columns[j].attr).cat("/>")}u.cat("</tr>")}e(u.string()).appendTo(this.$tbody)}for(var m=0;m<o;m++){var r=k[m];for(var h=0,t=this.columns.length;h<t;h++){var s=this.columns[h].mapping;if(s){r.cells[h].innerHTML=s(p[m])}}if(this.onRowDataBound){b.trigger(this.element,"rowDataBoundGrid",{row:r,dataItem:p[m]})}}for(;m<n;m++){e(k[k.length-1]).remove()}},updatePager:function(){var i=this.totalPages(this.total);var h=this.currentPage;var j=e(".t-pager",this.element);j.find(".t-arrow-next").parent().add(j.find(".t-arrow-last").parent()).toggleClass("t-state-disabled",h>=i).removeClass("t-state-hover");j.find(".t-arrow-prev").parent().add(j.find(".t-arrow-first").parent()).toggleClass("t-state-disabled",h==1).removeClass("t-state-hover");j.find(".t-page-i-of-n").each(function(){this.innerHTML=b.formatString('Page <input type="text" value="{0}" /> of {1}',h,i)});j.find(".t-numeric").each(e.proxy(function(l,k){this.numericPager(k,h,i)},this));e(".t-status-text",this.element).text(b.formatString("Displaying items {0} - {1} of {2}",this.firstItemInPage(),this.lastItemInPage(),this.total))},numericPager:function(o,m,p){var n=10;var h=1;if(m>n){var k=(m%n);h=(k==0)?(m-n)+1:(m-k)+1}var l=(h+n)-1;l=Math.min(l,p);var i=new b.stringBuilder();if(h>1){i.cat('<a class="t-link">...</a>')}for(var j=h;j<=l;j++){if(j==m){i.cat('<span class="t-state-active">').cat(j).cat("</span>")}else{i.cat('<a class="t-link">').cat(j).cat("</a>")}}if(l<p){i.cat('<a class="t-link">...</a>')}o.innerHTML=i.string()},updateSorting:function(){e(".t-header",this.element).each(e.proxy(function(l,m){var j=this.columns[l].sortDirection;var k=e(m).children(".t-link");var h=k.children(".t-icon");if(!j){h.hide()}else{if(h.length==0){h=e('<span class="t-icon"/>').appendTo(k)}h.toggleClass("t-arrow-up",j=="asc").toggleClass("t-arrow-down",j=="desc").show()}},this))},sanitizePage:function(h){var i=parseInt(h,10);if(isNaN(i)||i<1){return 1}return Math.min(i,this.totalPages())},totalPages:function(){return Math.ceil(this.total/this.pageSize)},firstItemInPage:function(){return this.total>0?(this.currentPage-1)*this.pageSize+1:0},lastItemInPage:function(){return Math.min(this.currentPage*this.pageSize,this.total)},dataBind:function(h){this.bindTo(h);this.updatePager();this.updateSorting()},rebind:function(h){this.sorted=[];this.currentPage=1;e.each(this.columns,function(){this.sortDirection=null;this.filters=[]});for(var j in h){var k=new RegExp(b.formatString("({0})=([^&]*)",j),"g");if(k.test(this.ajaxUrl)){this.ajaxUrl=this.ajaxUrl.replace(k,"$1="+h[j])}else{var i=new b.stringBuilder();i.cat(this.ajaxUrl);if(this.ajaxUrl.indexOf("?")<0){i.cat("?")}this.ajaxUrl=i.cat(j).cat("=").cat(h[j]).string()}}this.ajaxRequest()}});e.fn.tGrid=function(h){h=e.extend({},e.fn.tGrid.defaults,h);return this.each(function(){h=e.meta?e.extend({},h,e(this).data()):h;if(!e(this).data("tGrid")){var i=new b.grid(this,h);e(this).data("tGrid",i);if(i.$tbody.find("tr.t-no-data").length){i.ajaxRequest()}}})};e.fn.tGrid.defaults={columns:[],plugins:[],currentPage:1,pageSize:10,queryString:{page:"page",size:"size",orderBy:"orderBy",filter:"filter"}}})(jQuery);
So I am unsure what to look at next? Is there an uncompressed version of the script that I can use to try and debug?
0
Accepted
Hi Andy McShane,
This could mean the JSON you are trying to bind to is not valid JavaScript for some reason. The eval block is converting the passed string to JSON. You can check with firebug what is the returned output and see if it is valid JSON or not.
If this does not help I would ask you to provide a sample project which demonstrates the problem you are experiencing.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
This could mean the JSON you are trying to bind to is not valid JavaScript for some reason. The eval block is converting the passed string to JSON. You can check with firebug what is the returned output and see if it is valid JSON or not.
If this does not help I would ask you to provide a sample project which demonstrates the problem you are experiencing.
Regards,
Atanas Korchev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Andy McShane
Top achievements
Rank 1
answered on 10 Feb 2010, 04:07 PM
Thanks, I finally figured it out, dont know how I missed it but I was not creating a GridModel to be returned instead of my View and therefore there was loads of HTML in my return from my filtering/sorting call!!! Boy do I feel stupid now!!!
Sorry for wasting your time! :-(
Sorry for wasting your time! :-(
0
Alan Mosley
Top achievements
Rank 1
answered on 23 Apr 2010, 06:04 AM
I also get an error from this script if i try to use any ajax in the grid, are you getting error at same char 4048?
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.21022; .NET CLR 3.5.30428; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.1; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; .NET4.0C; .NET4.0E)
Timestamp: Fri, 23 Apr 2010 05:03:16 UTC
Message: Syntax error
Line: 1
Char: 4048
Code: 0
URI: http://localhost:61337/Scripts/telerik.grid.min.js