Defining columns in the datasource

I am attempting to export a JavaScript ejgrid with a backend in .net mvc. 

I am using dynamic columns, and get a null reference. 

I found the article explaining that we need to "ensure that the columns bound to the grid are defined in the grid data source before exporting."

How do I go about ensuring that they are defined in the datasource. I do not see any references on how to do it.  

7 Replies

BE Becky February 6, 2018 03:13 AM UTC

I also forgot to mention that my data source has a field attribute with the field name attached to it to correspond with the column field name while also having a headertext. 

Update: my datasources are dynamic objects which give me the error. I thought it could have been from the options of columns being moved, or the allow grouping that could be the problem. I tried bringing the data in via 

" toolbarClick: function(args) {
                            if (args.itemName === "Excel Export") {
                                //exportGrid(args);
                                //alert('hello');
                                args.cancel = true;
                                //alert('part 2');
                                this.model["currentData"] = JSON.stringify(this.model.dataSource);

                                this.export(spaceManagementAreaUrl + "Grid/ExcelExport"); // Excel Export method.
                            }"

But it won't let me serialize by dynamic objects. 

Every route I try to take seems to generate the same response of null reference. 


KM Kuralarasan Muthusamy Syncfusion Team February 6, 2018 01:47 PM UTC

Hi Nicholas, 

Thanks for contacting Syncfusion support.  

We have unable to reproduce the problem at our end, So we have prepare the sample demo for you  
Please refer the sample demo: 

If you still facing this issue please get back to us with the following details, 
  1. Share screenshot with replication procedure and video demonstration of the issue
  2. Share the code behind and view page.


Regards, 
Kuralarasan M 



BE Becky February 6, 2018 03:31 PM UTC

Thank you. This would most likely work if I wasn't using a JObject with unknown attributes. 

I am converting objects from the database into JObjects (dynamic objects) to the grid. 

I get a Json back in the to the ds.Value and convert it to a string...

The problem arises at this line 
currentData = JsonConvert.DeserializeObject<IEnumerable<JObject>>(str);

i get an error stating that I cannot convert a JsonArray :

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Newtonsoft.Json.Linq.JObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'dataSource', line 1, position 14.'


I have tried to convert to a JsonArray, to Serialize and Deserialize twice... and various other options I have found online, but nothing seems to be working. 

I am hoping someone maybe ran into this issue before and a there could be a solution in how to deseralize the returned datasource into a list of JObjects. Hopefully this is one of my issues. 


BE Becky February 7, 2018 03:26 AM UTC

I was able to convert the returned Json string into a list of dynamic objects, but I still get the null reference despite my jobect  looking similar to the below 
{"Fieldname": "value"}




KM Kuralarasan Muthusamy Syncfusion Team February 7, 2018 01:33 PM UTC

Hi Nicholas, 

Thanks for contacting Syncfusion support.  

We could see you are using the plain object to deserialize the Grid dataSource from JSON string. This will lead to the reported error which is the common issue. Since Grid Exporting requires Business object model to get the property value, it will not get a  property value from the plain object and leads an exception. 

To overcome this, problem, we can create a class using TypeBuilder concept. We have discussed this in the following KB. 


If you want to further details please get back to us with the following details, 
1.If you get any issue then share screenshot or video demonstration of the issu 
2. Share the code example of view page and code behind.. 


Regards, 
Kuralarasan M 



BE Becky February 12, 2018 05:00 PM UTC

Thank you!

With a  bit of tweeking for the ejGrid, this worked very well. 


KM Kuralarasan Muthusamy Syncfusion Team February 13, 2018 06:14 AM UTC

Hi Nicholas,

Thanks for the update. We are happy to hear that your requirement has been resolved. Please get back to us, if you require further assistance on this.

Regards, 
Kuralarasan M 
  


Loader.
Up arrow icon