Linking grids |
On of the more powerful features of the grid control is that they can be linked together to create parent child relationships. To link a child grid simply add it to the parent control using the LinkedControl property. The grids are linked by associating the column in the child grid specified as a ForeignKey with the column in the parent grid identified as a PrimaryKey. The sample also demonstrates use of the client-side event RowSelected to set the tab label using the client-side columnValue. method |
Loading...
Loading...
Loading...
Razor code
var customerColumns = new List
{
new GridColumn("customerid", "CustomerID") {PrimaryKey = true },
new GridColumn("firstname", "Forename"),
new GridColumn("lastname", "Surname"),
new GridColumn("email", "Email Address") {Format = FormatType.Email },
new GridColumn("address", "Address"),
new GridColumn("city", "City") { InitialSortOrder = SortOrder.Desc},
new GridColumn("postalcode", "Post Code")
};
var invoiceColumns = new List
{
new GridColumn("invoiceid", "Invoice ID") {PrimaryKey = true },
new GridColumn("customerid", "Customer ID") {ForeignKey = true, DataOnly = true },
new GridColumn("invoicedate", "Date"),
new GridColumn("billingaddress", "Address"),
new GridColumn("billingcity", "City"),
new GridColumn("billingstate", "State"),
new GridColumn("billingcountry", "Country"),
new GridColumn("billingpostalcode", "Post Code")
};
var invoiceItemColumns = new List
{
new GridColumn("invoicelineid", "Line ID"),
new GridColumn("invoiceid", "Invoice ID") {ForeignKey = true, DataOnly = true },
new GridColumn("trackid", "Track ID") {Lookup = new Lookup("tracks","trackid","name")},
new GridColumn("unitprice", "Price") {Format = "C"},
new GridColumn("quantity", "Qty")
};
var invoiceLineGrid = new GridModel("Invoice_items");
invoiceLineGrid.Columns = invoiceItemColumns;
invoiceLineGrid.Caption = "Invoice Lines";
invoiceLineGrid.PageSize = 5;
invoiceLineGrid.ToolbarPosition = ToolbarPosition.Hidden;
var invoiceGrid = new GridModel("Invoices");
invoiceGrid.Columns = invoiceColumns;
invoiceGrid.LinkedGrid = invoiceLineGrid;
invoiceGrid.Caption = "Invoices";
invoiceGrid.PageSize = 5;
invoiceGrid.ToolbarPosition = ToolbarPosition.Hidden;
var customerGrid = new GridModel(DataSourceType.SQLite, "Chinook(sqlite)", "Customers");
customerGrid.Columns = customerColumns;
customerGrid.LinkedGrid = invoiceGrid;
customerGrid.PageSize = 5;
@(await new DbNetSuiteCore.GridControl(HttpContext).Render(customerGrid))
@(await new DbNetSuiteCore.GridControl(HttpContext).Render(invoiceGrid))
@(await new DbNetSuiteCore.GridControl(HttpContext).Render(invoiceLineGrid))