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.
I wanted to provide you with an update on the status of this case. After further review, I was able to locate the issue, however, have not found a workaround yet. The issue lies in passing anything but a List back as your JSON data. For example, when you simply pass the list of items back you will get no issue after making the necessary changes in your grid. However, when you try passing back DataResult, you receive the error you referenced earlier. This being said, I am trying to find a way to do paging remotely such that you do not need to pass back the total records. This way, we could just pass but the JSON string which contains the list. I will get back to you on Monday by the end of the day with more information. In the meantime, if you want to try and do paging locally and just pass the list, you should get the results you are looking for.
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.
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.