plok77
Nov 03, 2021, 5:42 PM
We're having trouble making use of the Row Widget Plugin. We want to display a grid of child rows when a row in the main grid is expanded. The v7 Examples Site doesn't have an example of how to do this.
Here is the code for our page:
@page
@model SPS.Web.Pages.Auth.RowWidgetTestModel
@{
ViewData["Title"] = "GridPanel RowWidget";
}
<ext-viewport layout="Anchor">
<items>
<ext-gridPanel title="GridPanel" width="960" height="640" frame="true">
<store>
<ext-store storeId="StoreCompanies" data="Model.GridData.ToList<object>()">
<fields>
<ext-integerDataField name="id" />
<ext-stringDataField name="name" />
<ext-stringDataField name="address" />
<ext-dataField name="contacts" type="Array" />
</fields>
</ext-store>
</store>
<columns>
<ext-column text="Id" dataIndex="id" width="80" />
<ext-column text="Name" dataIndex="name" width="100" />
<ext-column text="Address" dataIndex="address" width="150" />
</columns>
<plugins>
<ext-rowWidgetPlugin>
<widget>
<ext-gridPanel autoLoad="true">
<customConfig>
<ext-add key="store">
<ext-add key="data" value="{record.contacts}"></ext-add>
</ext-add>
</customConfig>
<bind>
<ext-add key="title" value="Contacts"></ext-add>
</bind>
<columns>
<ext-column text="Id" dataIndex="id" width="50"></ext-column>
<ext-numberColumn text="Name" dataIndex="name" width="150"></ext-numberColumn>
<ext-numberColumn text="Email" dataIndex="email" width="150"></ext-numberColumn>
</columns>
</ext-gridPanel>
</widget>
</ext-rowWidgetPlugin>
</plugins>
</ext-gridPanel>
</items>
</ext-viewport>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace SPS.Web.Pages.Auth
{
public class RowWidgetTestModel : PageModel
{
public List<Company> GridData { get; set; }
public void OnGet()
{
this.GridData ??= new List<Company>
{
new Company
{
Id = 111, Name = "3m Co", Address = "Colombus",
Contacts = new List<Company.Contact>
{
new Company.Contact
{
Id = 1,
Name = "John Patt",
Email = "test89@test.com"
},
new Company.Contact
{
Id = 2,
Name = "Rod Max",
Email = "test53@test.com"
},
new Company.Contact
{
Id = 3,
Name = "Mary H",
Email = "test123@test.com"
}
}
},
new Company
{
Id = 112, Name = "General Electric Company", Address = "London",
Contacts = new List<Company.Contact>
{
new Company.Contact
{
Id = 4,
Name = "Jeff Earls",
Email = "test223@test.com"
},
new Company.Contact
{
Id = 5,
Name = "Pam Dam",
Email = "test44@test.com"
}
}
}
};
}
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public List<Contact> Contacts { get; set; }
public class Contact
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
}
}
}
When the page runs, the following error is reported in the browser on expanding a row:
Uncaught Error: You're trying to decode an invalid JSON String: {record.contacts}
at new Ext.Error (ext-all-debug.js:2770)
at Function.raise (ext-all-debug.js:2835)
at Object.Ext.raise (ext-all-debug.js:2916)
at Object.Ext.JSON.me.decode (ext-all-debug.js:57326)
at me.getRoot (extnet-all-debug.js:11373)
at constructor.me.getRoot (extnet-all-debug.js:11372)
at constructor.readRecords (ext-all-debug.js:98356)
at constructor.read (ext-all-debug.js:98276)
at constructor.read (ext-all-debug.js:99713)
at constructor.doExecute (ext-all-debug.js:91947)
Please can you advise what changes we need to make in order to get this sample to work?
Thanks
Paul
Here is the code for our page:
@page
@model SPS.Web.Pages.Auth.RowWidgetTestModel
@{
ViewData["Title"] = "GridPanel RowWidget";
}
<ext-viewport layout="Anchor">
<items>
<ext-gridPanel title="GridPanel" width="960" height="640" frame="true">
<store>
<ext-store storeId="StoreCompanies" data="Model.GridData.ToList<object>()">
<fields>
<ext-integerDataField name="id" />
<ext-stringDataField name="name" />
<ext-stringDataField name="address" />
<ext-dataField name="contacts" type="Array" />
</fields>
</ext-store>
</store>
<columns>
<ext-column text="Id" dataIndex="id" width="80" />
<ext-column text="Name" dataIndex="name" width="100" />
<ext-column text="Address" dataIndex="address" width="150" />
</columns>
<plugins>
<ext-rowWidgetPlugin>
<widget>
<ext-gridPanel autoLoad="true">
<customConfig>
<ext-add key="store">
<ext-add key="data" value="{record.contacts}"></ext-add>
</ext-add>
</customConfig>
<bind>
<ext-add key="title" value="Contacts"></ext-add>
</bind>
<columns>
<ext-column text="Id" dataIndex="id" width="50"></ext-column>
<ext-numberColumn text="Name" dataIndex="name" width="150"></ext-numberColumn>
<ext-numberColumn text="Email" dataIndex="email" width="150"></ext-numberColumn>
</columns>
</ext-gridPanel>
</widget>
</ext-rowWidgetPlugin>
</plugins>
</ext-gridPanel>
</items>
</ext-viewport>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace SPS.Web.Pages.Auth
{
public class RowWidgetTestModel : PageModel
{
public List<Company> GridData { get; set; }
public void OnGet()
{
this.GridData ??= new List<Company>
{
new Company
{
Id = 111, Name = "3m Co", Address = "Colombus",
Contacts = new List<Company.Contact>
{
new Company.Contact
{
Id = 1,
Name = "John Patt",
Email = "test89@test.com"
},
new Company.Contact
{
Id = 2,
Name = "Rod Max",
Email = "test53@test.com"
},
new Company.Contact
{
Id = 3,
Name = "Mary H",
Email = "test123@test.com"
}
}
},
new Company
{
Id = 112, Name = "General Electric Company", Address = "London",
Contacts = new List<Company.Contact>
{
new Company.Contact
{
Id = 4,
Name = "Jeff Earls",
Email = "test223@test.com"
},
new Company.Contact
{
Id = 5,
Name = "Pam Dam",
Email = "test44@test.com"
}
}
}
};
}
public class Company
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public List<Contact> Contacts { get; set; }
public class Contact
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
}
}
}
When the page runs, the following error is reported in the browser on expanding a row:
Uncaught Error: You're trying to decode an invalid JSON String: {record.contacts}
at new Ext.Error (ext-all-debug.js:2770)
at Function.raise (ext-all-debug.js:2835)
at Object.Ext.raise (ext-all-debug.js:2916)
at Object.Ext.JSON.me.decode (ext-all-debug.js:57326)
at me.getRoot (extnet-all-debug.js:11373)
at constructor.me.getRoot (extnet-all-debug.js:11372)
at constructor.readRecords (ext-all-debug.js:98356)
at constructor.read (ext-all-debug.js:98276)
at constructor.read (ext-all-debug.js:99713)
at constructor.doExecute (ext-all-debug.js:91947)
Please can you advise what changes we need to make in order to get this sample to work?
Thanks
Paul