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.
Hello Johan,
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.