PDA

View Full Version : Deeply nested JSON issues in GridPanel



arthurakay
6 Jul 2010, 6:32 AM
I've spent a bunch of time looking at other threads on the subject but none really seem to solve my problem.

I have a GridPanel() which receives JSON data from the server. The JSON data contains several levels of nested information - and the issue I'm having is that data nested further than 2 levels will not be displayed (and actually breaks my grid).

Here's the code for my grid - the grid itself displays just fine on the screen:


var appraisalListGrid = new Ext.grid.GridPanel({
store: appraisalListStore,
cm: new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
header: 'Appraisal #',
width: 75,
sortable: true,
dataIndex: 'AppraisalNumber',
editor: new Ext.form.TextField({ allowBlank: false })
}, {
header: 'Status',
width: 100,
sortable: true,
dataIndex: 'StatusDisplayName',
editor: new Ext.form.TextField({ allowBlank: false })
}, {
header: 'Customer Name',
width: 100,
sortable: true,
dataIndex: 'Borrower.LastName',
editor: new Ext.form.TextField({ allowBlank: false })
}, {
header: 'Appraiser',
width: 150,
sortable: true,
dataIndex: 'Appraiser.CompanyName',
editor: new Ext.form.TextField({ allowBlank: false })
}, {
header: 'Appointment Date',
width: 100,
sortable: true,
dataIndex: 'AppointmentDate',
editor: new Ext.form.DateField({ allowBlank: false })
}, {
header: 'Appointment Time',
width: 100,
sortable: true,
dataIndex: 'AppointmentTime',
editor: new Ext.form.TimeField({ allowBlank: false })
}])
});


If I pass the following JSON to the data store (no more than 2 levels deep for each record), the rows load just fine and display the data perfectly. NOTE: I'm passing the metadata for the grid/store in the JSON.


{"root":[{"Id":"4f04af33-00ca-4baa-8130-4705b80e5699","Borrower":{"Id":"97a92a86-4423-4bce-ba67-8637bdc1e675","FirstName":"Borrower","LastName":"Name","Company":"None","Phone":null,"Cell":"8923429","Fax":null,"Work":null,"County":null,"Email":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"Client":{"Id":"b2ba8e30-af6c-4a0e-babb-38084eb0feeb","Company":{"Id":"14e94e9f-0b90-4041-a96a-c63d0e8b6673","Name":"Client Company1","PhoneNumber":"19874321","FaxNumber":"12312908","EmailAddress":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"Contact":{"Id":"d85a8e90-484c-4290-97f9-84ccc5eb2424","FirstName":"John","LastName":"Doe Client","Company":null,"Phone":null,"Cell":"10984321","Fax":null,"Work":null,"County":null,"Email":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"IsManager":false,"User":null},"Appraiser":{"Id":"6b23ee74-773c-4b0b-9314-6c893b4e2412","CompanyName":"Appraiser Company 1","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"},"PhoneNumber":"1234891","FaxNumber":null,"CellNumber":"12345489","Email":"[email protected]","VendorWebsiteAddress":null,"VendorWebsiteLogin":null,"VendorWebsitePassword":null},"StatusId":"","StatusDisplayName":"","OnHoldReason":"","TypeId":"20f16b17-91fe-4415-ac94-04b17214c82d","TypeDisplayName":"Full URAR 2-4 Unit Income","TransactionTypeId":"2f20c137-7fd4-4ebc-aa1f-4e121a5dbbeb","TransactionTypeDisplayName":"Refinance","LoanNumber":"","FhaCaseNumber":"","LenderNumber":"","AppraisalNumber":"10-0001","LoanAmount":"","PurchasePrice":"","AppointmentDate":"","AppointmentTime":"","DateDue":"","DateCompleted":"","OrderDate":"7/5/2010","CodRequested":false,"AppraiserInvoiceAmount":"0.00000","InvoiceAmount":"0.00000","DatePaid":"","CheckNumber":"","Comments":""}],"totalCount":1,"metaData":{"fields":[{"name":"Id","mapping":"Id"},{"name":"Borrower.Id","mapping":"Borrower.Id"},{"name":"Borrower.FirstName","mapping":"Borrower.FirstName"},{"name":"Borrower.LastName","mapping":"Borrower.LastName"},{"name":"Borrower.Company","mapping":"Borrower.Company"},{"name":"Borrower.Phone","mapping":"Borrower.Phone"},{"name":"Borrower.Cell","mapping":"Borrower.Cell"},{"name":"Borrower.Fax","mapping":"Borrower.Fax"},{"name":"Borrower.Work","mapping":"Borrower.Work"},{"name":"Borrower.County","mapping":"Borrower.County"},{"name":"Borrower.Email","mapping":"Borrower.Email"},{"name":"Client.Id","mapping":"Client.Id"},{"name":"Client.IsManager","mapping":"Client.IsManager"},{"name":"Appraiser.Id","mapping":"Appraiser.Id"},{"name":"Appraiser.CompanyName","mapping":"Appraiser.CompanyName"},{"name":"Appraiser.PhoneNumber","mapping":"Appraiser.PhoneNumber"},{"name":"Appraiser.FaxNumber","mapping":"Appraiser.FaxNumber"},{"name":"Appraiser.CellNumber","mapping":"Appraiser.CellNumber"},{"name":"Appraiser.Email","mapping":"Appraiser.Email"},{"name":"Appraiser.VendorWebsiteAddress","mapping":"Appraiser.VendorWebsiteAddress"},{"name":"Appraiser.VendorWebsiteLogin","mapping":"Appraiser.VendorWebsiteLogin"},{"name":"Appraiser.VendorWebsitePassword","mapping":"Appraiser.VendorWebsitePassword"},{"name":"StatusId","mapping":"StatusId"},{"name":"StatusDisplayName","mapping":"StatusDisplayName"},{"name":"OnHoldReason","mapping":"OnHoldReason"},{"name":"TypeId","mapping":"TypeId"},{"name":"TypeDisplayName","mapping":"TypeDisplayName"},{"name":"TransactionTypeId","mapping":"TransactionTypeId"},{"name":"TransactionTypeDisplayName","mapping":"TransactionTypeDisplayName"},{"name":"LoanNumber","mapping":"LoanNumber"},{"name":"FhaCaseNumber","mapping":"FhaCaseNumber"},{"name":"LenderNumber","mapping":"LenderNumber"},{"name":"AppraisalNumber","mapping":"AppraisalNumber"},{"name":"LoanAmount","mapping":"LoanAmount"},{"name":"PurchasePrice","mapping":"PurchasePrice"},{"name":"AppointmentDate","mapping":"AppointmentDate"},{"name":"AppointmentTime","mapping":"AppointmentTime"},{"name":"DateDue","mapping":"DateDue"},{"name":"DateCompleted","mapping":"DateCompleted"},{"name":"OrderDate","mapping":"OrderDate"},{"name":"CodRequested","mapping":"CodRequested"},{"name":"AppraiserInvoiceAmount","mapping":"AppraiserInvoiceAmount"},{"name":"InvoiceAmount","mapping":"InvoiceAmount"},{"name":"DatePaid","mapping":"DatePaid"},{"name":"CheckNumber","mapping":"CheckNumber"},{"name":"Comments","mapping":"Comments"}],"root":"root","totalProperty":"totalCount"}}


To simply the above JSON, here's the metadata property:


"metaData":{"fields":[{"name":"Id","mapping":"Id"},{"name":"Borrower.Id","mapping":"Borrower.Id"},{"name":"Borrower.FirstName","mapping":"Borrower.FirstName"},{"name":"Borrower.LastName","mapping":"Borrower.LastName"},{"name":"Borrower.Company","mapping":"Borrower.Company"},{"name":"Borrower.Phone","mapping":"Borrower.Phone"},{"name":"Borrower.Cell","mapping":"Borrower.Cell"},{"name":"Borrower.Fax","mapping":"Borrower.Fax"},{"name":"Borrower.Work","mapping":"Borrower.Work"},{"name":"Borrower.County","mapping":"Borrower.County"},{"name":"Borrower.Email","mapping":"Borrower.Email"},{"name":"Client.Id","mapping":"Client.Id"},{"name":"Client.IsManager","mapping":"Client.IsManager"},{"name":"Appraiser.Id","mapping":"Appraiser.Id"},{"name":"Appraiser.CompanyName","mapping":"Appraiser.CompanyName"},{"name":"Appraiser.PhoneNumber","mapping":"Appraiser.PhoneNumber"},{"name":"Appraiser.FaxNumber","mapping":"Appraiser.FaxNumber"},{"name":"Appraiser.CellNumber","mapping":"Appraiser.CellNumber"},{"name":"Appraiser.Email","mapping":"Appraiser.Email"},{"name":"Appraiser.VendorWebsiteAddress","mapping":"Appraiser.VendorWebsiteAddress"},{"name":"Appraiser.VendorWebsiteLogin","mapping":"Appraiser.VendorWebsiteLogin"},{"name":"Appraiser.VendorWebsitePassword","mapping":"Appraiser.VendorWebsitePassword"},{"name":"StatusId","mapping":"StatusId"},{"name":"StatusDisplayName","mapping":"StatusDisplayName"},{"name":"OnHoldReason","mapping":"OnHoldReason"},{"name":"TypeId","mapping":"TypeId"},{"name":"TypeDisplayName","mapping":"TypeDisplayName"},{"name":"TransactionTypeId","mapping":"TransactionTypeId"},{"name":"TransactionTypeDisplayName","mapping":"TransactionTypeDisplayName"},{"name":"LoanNumber","mapping":"LoanNumber"},{"name":"FhaCaseNumber","mapping":"FhaCaseNumber"},{"name":"LenderNumber","mapping":"LenderNumber"},{"name":"AppraisalNumber","mapping":"AppraisalNumber"},{"name":"LoanAmount","mapping":"LoanAmount"},{"name":"PurchasePrice","mapping":"PurchasePrice"},{"name":"AppointmentDate","mapping":"AppointmentDate"},{"name":"AppointmentTime","mapping":"AppointmentTime"},{"name":"DateDue","mapping":"DateDue"},{"name":"DateCompleted","mapping":"DateCompleted"},{"name":"OrderDate","mapping":"OrderDate"},{"name":"CodRequested","mapping":"CodRequested"},{"name":"AppraiserInvoiceAmount","mapping":"AppraiserInvoiceAmount"},{"name":"InvoiceAmount","mapping":"InvoiceAmount"},{"name":"DatePaid","mapping":"DatePaid"},{"name":"CheckNumber","mapping":"CheckNumber"},{"name":"Comments","mapping":"Comments"}],"root":"root","totalProperty":"totalCount"}


But the grid completely fails to display any rows the moment I add more levels of nesting to the JSON string. The grid loads the following (as many as 4 levels deep) but displays no rows:


{"root":[{"Id":"4f04af33-00ca-4baa-8130-4705b80e5699","Borrower":{"Id":"97a92a86-4423-4bce-ba67-8637bdc1e675","FirstName":"Borrower","LastName":"Name","Company":"None","Phone":null,"Cell":"8923429","Fax":null,"Work":null,"County":null,"Email":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"Client":{"Id":"b2ba8e30-af6c-4a0e-babb-38084eb0feeb","Company":{"Id":"14e94e9f-0b90-4041-a96a-c63d0e8b6673","Name":"Client Company1","PhoneNumber":"19874321","FaxNumber":"12312908","EmailAddress":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"Contact":{"Id":"d85a8e90-484c-4290-97f9-84ccc5eb2424","FirstName":"John","LastName":"Doe Client","Company":null,"Phone":null,"Cell":"10984321","Fax":null,"Work":null,"County":null,"Email":"[email protected]","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"}},"IsManager":false,"User":null},"Appraiser":{"Id":"6b23ee74-773c-4b0b-9314-6c893b4e2412","CompanyName":"Appraiser Company 1","Address":{"Street":"1234 street","Street2":null,"City":"NewCity","State":"ST","ZipCode":"12343"},"PhoneNumber":"1234891","FaxNumber":null,"CellNumber":"12345489","Email":"[email protected]","VendorWebsiteAddress":null,"VendorWebsiteLogin":null,"VendorWebsitePassword":null},"StatusId":"","StatusDisplayName":"","OnHoldReason":"","TypeId":"20f16b17-91fe-4415-ac94-04b17214c82d","TypeDisplayName":"Full URAR 2-4 Unit Income","TransactionTypeId":"2f20c137-7fd4-4ebc-aa1f-4e121a5dbbeb","TransactionTypeDisplayName":"Refinance","LoanNumber":"","FhaCaseNumber":"","LenderNumber":"","AppraisalNumber":"10-0001","LoanAmount":"","PurchasePrice":"","AppointmentDate":"","AppointmentTime":"","DateDue":"","DateCompleted":"","OrderDate":"7/5/2010","CodRequested":false,"AppraiserInvoiceAmount":"0.00000","InvoiceAmount":"0.00000","DatePaid":"","CheckNumber":"","Comments":""}],"totalCount":1,"metaData":{"fields":[{"name":"Id","mapping":"Id"},{"name":"Borrower.Id","mapping":"Borrower.Id"},{"name":"Borrower.FirstName","mapping":"Borrower.FirstName"},{"name":"Borrower.LastName","mapping":"Borrower.LastName"},{"name":"Borrower.Company","mapping":"Borrower.Company"},{"name":"Borrower.Phone","mapping":"Borrower.Phone"},{"name":"Borrower.Cell","mapping":"Borrower.Cell"},{"name":"Borrower.Fax","mapping":"Borrower.Fax"},{"name":"Borrower.Work","mapping":"Borrower.Work"},{"name":"Borrower.County","mapping":"Borrower.County"},{"name":"Borrower.Email","mapping":"Borrower.Email"},{"name":"Borrower.Address.Street","mapping":"Borrower.Address.Street"},{"name":"Borrower.Address.Street2","mapping":"Borrower.Address.Street2"},{"name":"Borrower.Address.City","mapping":"Borrower.Address.City"},{"name":"Borrower.Address.State","mapping":"Borrower.Address.State"},{"name":"Borrower.Address.ZipCode","mapping":"Borrower.Address.ZipCode"},{"name":"Client.Id","mapping":"Client.Id"},{"name":"Client.Company.Id","mapping":"Client.Company.Id"},{"name":"Client.Company.Name","mapping":"Client.Company.Name"},{"name":"Client.Company.PhoneNumber","mapping":"Client.Company.PhoneNumber"},{"name":"Client.Company.FaxNumber","mapping":"Client.Company.FaxNumber"},{"name":"Client.Company.EmailAddress","mapping":"Client.Company.EmailAddress"},{"name":"Client.Contact.Id","mapping":"Client.Contact.Id"},{"name":"Client.Contact.FirstName","mapping":"Client.Contact.FirstName"},{"name":"Client.Contact.LastName","mapping":"Client.Contact.LastName"},{"name":"Client.Contact.Company","mapping":"Client.Contact.Company"},{"name":"Client.Contact.Phone","mapping":"Client.Contact.Phone"},{"name":"Client.Contact.Cell","mapping":"Client.Contact.Cell"},{"name":"Client.Contact.Fax","mapping":"Client.Contact.Fax"},{"name":"Client.Contact.Work","mapping":"Client.Contact.Work"},{"name":"Client.Contact.County","mapping":"Client.Contact.County"},{"name":"Client.Contact.Email","mapping":"Client.Contact.Email"},{"name":"Client.IsManager","mapping":"Client.IsManager"},{"name":"Client.User.Id","mapping":"Client.User.Id"},{"name":"Client.User.UserName","mapping":"Client.User.UserName"},{"name":"Client.User.FullName","mapping":"Client.User.FullName"},{"name":"Client.User.UserType","mapping":"Client.User.UserType"},{"name":"Client.User.OwnerId","mapping":"Client.User.OwnerId"},{"name":"Client.User.OwnerType","mapping":"Client.User.OwnerType"},{"name":"Appraiser.Id","mapping":"Appraiser.Id"},{"name":"Appraiser.CompanyName","mapping":"Appraiser.CompanyName"},{"name":"Appraiser.Address.Street","mapping":"Appraiser.Address.Street"},{"name":"Appraiser.Address.Street2","mapping":"Appraiser.Address.Street2"},{"name":"Appraiser.Address.City","mapping":"Appraiser.Address.City"},{"name":"Appraiser.Address.State","mapping":"Appraiser.Address.State"},{"name":"Appraiser.Address.ZipCode","mapping":"Appraiser.Address.ZipCode"},{"name":"Appraiser.PhoneNumber","mapping":"Appraiser.PhoneNumber"},{"name":"Appraiser.FaxNumber","mapping":"Appraiser.FaxNumber"},{"name":"Appraiser.CellNumber","mapping":"Appraiser.CellNumber"},{"name":"Appraiser.Email","mapping":"Appraiser.Email"},{"name":"Appraiser.VendorWebsiteAddress","mapping":"Appraiser.VendorWebsiteAddress"},{"name":"Appraiser.VendorWebsiteLogin","mapping":"Appraiser.VendorWebsiteLogin"},{"name":"Appraiser.VendorWebsitePassword","mapping":"Appraiser.VendorWebsitePassword"},{"name":"StatusId","mapping":"StatusId"},{"name":"StatusDisplayName","mapping":"StatusDisplayName"},{"name":"OnHoldReason","mapping":"OnHoldReason"},{"name":"TypeId","mapping":"TypeId"},{"name":"TypeDisplayName","mapping":"TypeDisplayName"},{"name":"TransactionTypeId","mapping":"TransactionTypeId"},{"name":"TransactionTypeDisplayName","mapping":"TransactionTypeDisplayName"},{"name":"LoanNumber","mapping":"LoanNumber"},{"name":"FhaCaseNumber","mapping":"FhaCaseNumber"},{"name":"LenderNumber","mapping":"LenderNumber"},{"name":"AppraisalNumber","mapping":"AppraisalNumber"},{"name":"LoanAmount","mapping":"LoanAmount"},{"name":"PurchasePrice","mapping":"PurchasePrice"},{"name":"AppointmentDate","mapping":"AppointmentDate"},{"name":"AppointmentTime","mapping":"AppointmentTime"},{"name":"DateDue","mapping":"DateDue"},{"name":"DateCompleted","mapping":"DateCompleted"},{"name":"OrderDate","mapping":"OrderDate"},{"name":"CodRequested","mapping":"CodRequested"},{"name":"AppraiserInvoiceAmount","mapping":"AppraiserInvoiceAmount"},{"name":"InvoiceAmount","mapping":"InvoiceAmount"},{"name":"DatePaid","mapping":"DatePaid"},{"name":"CheckNumber","mapping":"CheckNumber"},{"name":"Comments","mapping":"Comments"}],"root":"root","totalProperty":"totalCount"}}


According to JSONLint, the JSON strings are valid. As far as I can tell, I'm correctly mapping the data onto my columns. Am I missing something, or does the JsonStore not support JSON nesting this deep?

Condor
6 Jul 2010, 6:53 AM
1. You should really try to use field names without '.' in them (only the mappings needs them).
2. Are Borrower, Borrower.Address, Client, Client.Company, Client.Contact, Client.User, Appraiser and Appraiser.Address always present for every record or are they optional? Your mappings will fail if they are optional!

arthurakay
6 Jul 2010, 7:03 AM
Thanks for the quick reply Condor. I realize thats a ton of JSON to read through, so I appreciate it :D

1. I tried using names without the "." and it didn't help, so I just left them in. Good point though.

2. These nested JSON objects are present for every record - they're built from DTOs on the back-end, so we're just serializing them. Some of the values might be empty strings, but the properties (like "Borrower.Address.ZipCode") will always be present, even if I'm not displaying it as a column in the grid.

arthurakay
6 Jul 2010, 8:42 AM
I see the problem. Some of my JSON values were "null" when they should have been empty strings. Valid JSON, but I'm guessing the JSON reader barfed on the nulls.