I have a hierarchical data grid that receives data from a json call fine. But I have problems with the child band. I don't know if it is the code or how the data is presented within the list from the json call.
<script type="text/javascript">
var data = @MyAcesData.AsRawJson()
$("#hierarchicalGrid").igHierarchicalGrid({ dataSource: data, odata: true, initialDataBindDepth: 0, autoGenerateLayouts: true, autoGenerateColumns: false, primaryKey: "Username", columns: [{ key: "Username", headerText: "Username", dataType: "string" }, {key: "EmplID", headerText: "EmplID", dataType: "string" }, {key: "Comment", headerText: "Comment", dataType: "string" }], features: [{name: 'Paging', type: "local", pageSize: 50}, { name: "Resizing"}, { name: 'ColumnMoving' }], columnLayouts: [ { key: "GroupName", primaryKey: "GroupName", foreignKey: "GroupMembers", autoGenerateLayouts: true, autoGenerateColumns: false, columns: [ { key: "GroupName", headerText: "UserName", dataType: "string", width: "100px" }, { key: "GroupDescription", headerText: "GroupDescription", dataType: "string", width: "100px" }, { key: "GroupMembers", headerText: "GroupMembers", dataType: "string", width: "100px" } ], features: [ { name: "Sorting", type: "local" }] }] });
</script>
The data comes as follows
[username],[EmplID],[comment],[GroupName],[GroupDescription],[GroupMembers]
with UserName,EmplID, and Comment repeating with the same values per username while values for GroupName, and GroupDescription continue to be unique. GroupMembers has the same data as UserName. All of the data is coming from a view, which is a join from Users ([username],[EmplID],[comment]) and Groups ([GroupName],[GroupDescription],[GroupMembers]). I would like a single row for UserName,EmplID, and Comment as if it were a groupby then expanding the child band would show [GroupName] and [GroupDescription].
When the initial grid opens, I get repeating rows of [username],[EmplID],[comment] and when I try to expand the child band, it throws a errormessage displaying:
Unable to get value of the property '_injectGrid': object is null or undefined.
For what its worth, this is written on C# Razor pages using ServiceStack to Bootstrap. Any and all help is greatly appreciated.
Hello Jason,
Can you send me a sample that demonstrates your issue, so that I can test and debug it on my side? Thanks in advance.
Regards,
Tsanna
I don't know if there is a neat way of displaying the code, or at least I don't know where to host it. I say that because I believe part of the problem I'm having is how the data is presented to the grid. The data is coming from a json ServiceStack call, See below:
<table id="hierarchicalGrid"></table>
var data = @UserInformation.AsRawJson()
$("#hierarchicalGrid").igHierarchicalGrid({
datasourcetype: 'json',
dataSource: data,
odata: true,
initialDataBindDepth: 0,
autoGenerateLayouts: false,
autoGenerateColumns: false,
columns:
[{ key: "Username", dataType: "string", headerText: "Username" },
{ key: "EmplID", dataType: "string", headerText: "EmplID" },
{ key: "Comment", dataType: "string", headerText: "Comment" }],
columnLayouts: [
{
key: "GroupInformation",
childrenDataProperty: "GroupInformation",
columnLayouts:
[{ key: "GroupName",
autoGenerateColumns: true}]
}]
});
That is what my code looks like in its current format. Running this code gives me exactly what I want on the parent band. The child band errors out with the message:
"Microsoft JScript runtime error: Unable to get value of the property 'dataType': object is null or undefined"
The data is now give to the grid as rawjson is from a list from a class that has fields "UserName, EmplID, Comment, and a property as a list that has fields "GroupName and GroupDescription" for my child band which will have multiple rows per one row of parent band. The name of the list that holds the child band information is "mygroup"
Thank you so much for your help Martin!
What I tried to do (not knowing what I needed to do) was try to test the c# code with static values so i knew how to format the data coming from the database through json. My hard code examples in c# within a razor page are below:
@{
List<SomeClassForTheSecondBand> MyGroup = new List<SomeClassForTheSecondBand>();List<SomeClassForTheFirstBand> UserInformation = new List<SomeClassForTheFirstBand>();
MyGroup.Add(new SomeClassForTheSecondBand() { GroupName = "GroupOne", GroupDescription = "Testing of GroupDescription" });
UserInformation.Add(new SomeClassForTheFirstBand() { Username = "Jason", EmplID = "999999", Comment = "This is a comment for Jason", GroupInformation = MyGroup });UserInformation.Add(new SomeClassForTheFirstBand() { Username = "Jeff", EmplID = "888888", Comment = "This is a comment for Jeff", GroupInformation = MyGroup });
}
[the rest of the below is the same as what is posted above]
Definition of class for SomeClassForTheFirstBand and SomeClassForTheSecondBand
public class SomeClassForTheFirstBand {
public string Username { get; set; } public string Fullname { get; set; } public string Comment { get; set; } public string Acctlocked { get; set; }public string EmplID { get; set; }public List<SomeClassForTheSecondBand> GroupInformation = new List<SomeClassForTheSecondBand>();
public class SomeClassForTheSecondBand
{ public string GroupName { get; set; } public string GroupDescription { get; set; }}
Using your syntax above for the data, I don't understand how I would be able prepare multiple rows for the second band. I understand how I can query a table and put that information in the list for the first band, but I don't quite understand how I can organize that information for the second band in what seems to be without a "List of a List", which is what I tried and didn't work.
For example, using the example of my code I posted, it seems like what you are telling me to try is equivalent to:
public class SomeClassForTheFirstBand{
public string Username { get; set; }public string Fullname { get; set; }public string Comment { get; set; }public string Acctlocked { get; set; }public string EmplID { get; set; }
class SomeClassForTheSecondBand
public string GroupName { get; set; } public string GroupDescription { get; set; }
UserInformation.Add(new SomeClassForTheFirstBand() { Username = "Jason", EmplID = "999999", Comment = "This is a comment for Jason", New SomeClassForTheSecondBand() {GroupName = "FirstGroupForJason", GroupDescription = "Description of First Group "})
UserInformation.Add(new SomeClassForTheFirstBand() { Username = "Jason", EmplID = "999999", Comment = "This is a comment for Jason", New SomeClassForTheSecondBand() {GroupName = "SecondGroupForJason", GroupDescription = "Description of Second Group "})
So, For each child band information that is different within what would be the same parent band, the parent information repeats in the rest of the row. Am I understanding you correctly?
dataSourceType:'json',
primaryKey:"EmplID",
//responseDataKey: data,
columns:[{ key:"Username", dataType: "string", headerText: "Username" },
{ key:"EmplID", dataType: "string", headerText: "EmplID" },
{ key:"Comment", dataType: "string", headerText: "Comment" }],
key:
"MyGroup",
responseDataKey:
"data",
autoGenerateColumns:
false,
primaryKey:"GroupName",
foreignKey: "GroupMembers",
columns: [{ key:
"GroupName", headerText: "UserName", dataType: "string" },
{ key:"GroupDescription", headerText: "GroupDescription", dataType: "string" }]
var data = [{"Username":"Jason","Comment":"This is a comment for Jason","EmplID":"999999"},{"Username":"Jeff","Comment":"This is a comment for Jeff","EmplID":"888888"}]
Thank you for your help Martin, I really appreciate your time. You and Jon Hogue really helped a lot. Take care.
Let me know if you need further assistance regarding this subject.
Best regards,Martin PavlovInfragistics, Inc.
Jason,
Thanks for posting the sample data. As Martin had mentioned, and as we discussed on the phone, the issue is with your child collection not being serialized from the .Net to the client. If you get that data into your data from the server, then you should have a working grid. Just make sure the name of the property with the child collections matches the key for the columnLayout.
Cheers,
Jon