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,
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.
Thank you, I can almost get it to work now. I have however run into some issues when moving the JavaScript code to it's own file. When the JS code is embedded in script tag in the asp layer everything seems to work, but when I place the JS code in a separate .js file that I include in the asp layer I get an error message saying the it cannot determine if the data type is XML or JSON. I've tried setting the dataSourceType to "json" without any luck. Please see attached sample.
I have found the reason why you were receiving this issue. The grid was unable to get the data from your backend because you were making the ResolveUrl call in the .js file. When placed in the Grid.js file, this code is not recognized the same way it is when it is in a .aspx file and does not run correctly. I was able to get this working by keeping all of the Grid.js file in the same place, but moving the $(document).ready() function back into the Default.aspx page. Inside of this function, I called ResolveUrl and then passed the data into the loadData function as a parameter. I have attached the rearranged sample. Please let me know if there is anything else I can assist you with.
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.
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.
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!