"Uncaught Error: There was an error parsing the JSON data and applying the defined data schema: The input data doesn't match the schema, the following field couldn't be mapped: MyKeyGuid"
I receive this error no matter what I do/set....what can I do here?
My Data:
{"Table":[{"MyKeyGuid":"9eb191d8-14bf-4159-b8a6-5da004afbc15","Name":"TestTitle","Agent":"TestData"}],"Table1":[{"OwnerGuid":"9eb191d8-14bf-4159-b8a6-5da004afbc15","Trxid":43182,"TrxDate":"2005-11-01T00:00:00","Rent":383.9874,"Suspended":false},{"MyKeyGuid":"9eb191d8-14bf-4159-b8a6-5da004afbc15","Trxid":71455,"TrxDate":"2017-05-01T00:00:00","Base":420.0240,"Suspended":false}]}
My Code (I have quite a bit commented out just to try and make this work.)
$("#myGrid").igHierarchicalGrid({ key: "Table", width: "100%", dataSource: data, dataSourceType: "json", //responseDataKey: "results", autoGenerateColumns: false, autofitLastColumn: false, primaryKey: "MyKeyGuid", columns: [ { key: "MyKeyGuid", headerText: "KeyGuid", dataType: "string", width: "20%" }, { key: "Name", headerText: "First Name", dataType: "string", width: "20%" }, { key: "Agent", headerText: "Title", dataType: "string", width: "20%" } ], autoGenerateLayouts: false,columnLayouts: [ { key: "Table1", autoGenerateColumns: false, autofitLastColumn: false, primaryKey: "MyKeyGuid", width: "100%", dataSource: data,columns: [{ key: "Trxid", headerText: "Trx", dataType: "number", width: "0%", hidden: true }, { key: "MyKeyGuid", headerText: "MyKey", dataType: "string", width: "20%" }, { key: "TrxDate", headerText: "TrxDate", dataType: "string", width: "20%" }, { key: "Rent", headerText: "Rent", dataType: "string", width: "20%" }, { key: "Suspended", headerText: "Suspended", dataType: "string", width: "0%", hidden: true } ] });
Hello William,In order to reproduce the behavior on my side I would highly appreciate if you could send me an isolated sample where the data set is created (if coming from a database please create a dummy data set for testing purposes) and set as data source for the igHierarachicalGrid. If not possible to create a sample, please provide me at least the data set, the controller and the view.By design igHierarachicalGrid bounding to a data set is accomplished in one of the following ways:Return the DataSet from the action method referenced by the grid’s DataSourceURL in the view.Construct a GridModel in the controller and return as the view’s model.More about these two approaches can be found here.Looking forward to hearing from you.
Hmm. My problem here is the format I get returned after parsing a dataSet is as I have shown. How can you bind the hierarchial grid to data in a dataset via javascript?
I am using tyhe following.
string JSONString = string.Empty; JSONString = JsonConvert.SerializeObject(dataSet); return JSONString;
Hello William,
What I observed in the provided snippet is that the data source is not in the correct format. I modified the data to a valid format as following:
var data1 = { "Table": [{ "MyKeyGuid": "9eb191d8-14bf-4159-b8a6-5da004afbc15", "Name": "TestTitle", "Agent": "TestData", "Table1": [{ "OwnerGuid": "9eb191d8-14bf-4159-b8a6-5da004afbc15", "Trxid": 43182, "TrxDate": "2005-11-01T00:00:00", "Rent": 383.9874, "Suspended": false }, { "MyKeyGuid": "9eb191d8-14bf-4159-b8a6-5da004afbc15", "Trxid": 71455, "TrxDate": "2017-05-01T00:00:00", "Base": 420.0240, "Suspended": false }] }], };
Additionally, I noticed that the values in “MyKeyGuid” column, which is set as primaryKey, are not unique. By design, igHierarachicalGrid uses the primaryKey to uniquely distinguish records, which means that all values should be unique. Having this in mind, I changed the primaryKey to “Trxid” column.
Attached you can find a sample with the modified data source which works as expected. Please test it and let me know whether it behaves as expected on your side.
In case this is not an accurate representation of what you are trying to achieve feel free to get back to me with more details regarding your requirement.
hgridSample.zip