We are using Infragistics 13.2 and ASP.NET and are trying to use a DataSourceURL pointing to a static WebMethod which returns a String back to the client, but we keep getting below exception when binding the datasource:
Unhandled exception at line 226, column 27387 in http://localhost:55765/igniteUI/js/infragistics.core.js0x800a138f - JavaScript runtime error: Unable to get property 'length' of undefined or null reference
We need to return a String:
This seems to be a general exception when returning a String from a DataSourceURL web method, but we cannot change to returning a specific object. Due to our data set being generated by user input at runtime we cannot know what columns will exist or how many. The only thing we have to work with is a C# DataTable (which cannot be serialized "as is" due to circular references) so we are building our own JSON and hence we need to return a String, not an object from the server web method.
Example:
In the attached example is a simplified case to illustrate my point. When the example code is executed as is, the JavaScript error above will be thrown. If the example is modified simply to return the object DataResult instead of the serialized version of the object (in other words, the .ToJSON() call is removed and the return type of the web method is changed to DataResult) everything works again.
Can you please look at this and provide a sample where the web method returns an already serialized object, that is a String, back to the client? I assume this has to do with flagging for parsing the string to a JS object, even if it is returned as a String from the web method.
Hello Johan Lundman,
Thank you for posting in our forums!
Thank you for the sample. I will need a little more time to look into this.
I will have another update on my findings for you tomorrow.
Hi Johan Lundman,
I need some more time to look into this.
In the interest of time, I have asked some of my colleagues from our Bulgarian office if they can help look into this.
We will have more information on this for you by tomorrow.
As it turns out, the problem lied in the fact that the object you were passing to the view was a string of JSON objects. To correct this, I made an ajax call to receive this string, which I then parsed into a JSON array. From there, after specifying the responseDataKey as Items, I was able to set my dataSource to the parsed JSON and retrieve TotalRecordsCount. Please see my attached sample for more insight in the comments. You will notice I commented out your manual paging statement, as this was causing no Items to be sent to the client. I believe the root of the problem is with your ToJSON() method. It seems to me that it is not formatting the data correctly as you had desired. Moving forward, you may want to edit this method to reformat the data so you can avoid performing those operations on the client.
Please let me know if you have any further questions on the matter.
I cannot get sorting to work in your example, it is the only remote operation and it does not trigger a call to GetGridData which of course is a requirement for me to be able to handle the event remotely and return a new fresh data set (since our data sets are huge I'll let our DB do the filtering & sorting).
Also, In your example the paging works but only since have set it to be a local operation (type: "local"), I need it to remain a remote operation.
Hello Johan,
I wanted to update you on my progress with working with your issue. I have found some very good resources which should help you resolve your issues. Please view this sample for more information on remote sorting: http://igniteui.com/grid/sorting-remote . This sample is a great example of performing remote sorting and should give you some insight on how to do it in your project. For remote paging, please view this thread: http://es.infragistics.com/community/forums/t/77099.aspx . You will see that Martin Pavlov has given a full sample of remote paging with MVC Wrappers at the end.
I hope this helps give you more insight on you issue. I will get back to you by the end of the day tomorrow with more information. Please do not hesitate to ask me any further questions.
I wanted to update you on the progress of this issue. The reason we have been unable to perform the sorting and paging is because we have instantiated the grid in the ajax call. I had previously done this to deal with the original issue you were receiving. I have now resolved the original issue you had with getting 'cannot read property length of undefined' when requesting the data without editing the data on the client side. I will continue to work with the remote Paging and Sorting and get back to you as soon as I have more information for you. Please do not hesitate to contact me with more questions.
Thank you very much for your patience. I have attached a fully functioning version of the original project you sent me. There was some custom editing server side which had to be done to correctly parse the data for the grid, and some changes I made to getting and setting the query string. Please let me know if you have any further questions.
Is there anything else I can assist you with on the matter? Please do not hesitate to contact me with more questions.
That is great news! Please do not hesitate to contact me if I can be of further assistance.
I have managed to fully implement the desired behavior in our solution now. Thank you so much for all of your help Joe, it is much appreciated!
I am very glad that implementation worked for you! You can pass custom parameters to your web method GetGridData with the use of an ajax call. This will allow you to send data from the client side over to the backend for data storing and processing. Please view this link for a great in depth guide on implementing this: http://encosia.com/using-complex-types-to-make-calling-services-less-complex/ .
Ignite UI will automatically pass filter and sort information back to your web method upon requests of these features. In fact, your current implementation is already doing this. The data is passed through on a query string after a request which you can parse to get the data passed over from the client. Please scroll down to remote filtering in the following link to see how the grid encodes filtering information: http://help.infragistics.com/doc/jQuery/2014.1/CLR4.0/ . You can view the query string after implementing sort in your current project to see how your grid is encoding sorting information. Please note that the names of the data being passed back can be edited in the options of the filtering feature. Please let me know if I can be of further assistance.
Thank you Joe, that worked nicely! Finally I'd just like to know if there's a way of passing some custom parameters to my web method GetGridData? There are some ID's and user information that I need to keep track of. I'd also like to know how I can pass filter and sort information back to my web method so that I can return the correct subset.