Replies: 2 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
I will use the Order grid in Northwind sample to show you how to do.
Step 1Originally, the row/entity returned from OrderService/List looks as below: {
"OrderID": 11077,
"CustomerID": "RATTC",
"EmployeeID": 1,
"OrderDate": "2016-11-06T00:00:00.000",
"RequiredDate": "2016-12-03T00:00:00.000",
"ShipVia": 2,
"Freight": 8.5300,
"ShipName": "Rattlesnake Canyon Grocery",
"ShipAddress": "2817 Milton Dr.",
"ShipCity": "Albuquerque",
"ShipRegion": "NM",
"ShipPostalCode": "87110",
"ShipCountry": "USA",
"CustomerCompanyName": "Rattlesnake Canyon Grocery",
"EmployeeFullName": "Nancy Davolio",
"EmployeeGender": 2,
"ShipViaCompanyName": "United Package"
} We want to add a property ...
[DisplayName("Products")]
[NotMapped]
[LinkingSetRelation(typeof(OrderDetailRow), "OrderID", "ProductID")]
[MinSelectLevel(SelectLevel.List)]
public List<Int32> ProductList
{
get { return Fields.ProductList[this]; }
set { Fields.ProductList[this] = value; }
}
public class RowFields : RowFieldsBase
{
...
public ListField<Int32> ProductList;
} Now, the row/entity returned from OrderService/List looks like below: {
"OrderID": 11077,
....
"ProductList": [2, 3, 4, 6, 7, 8, 10, 12, 13, 14, 16, 20, 23, 32, 39, 41, 46, 52, 55, 60, 64, 66, 73, 75, 77, 17]
....
} Step 2We now have product id list, but we want to display it as drop down list and use product name as text. namespace StartSharp1.Northwind {
@Serenity.Decorators.registerFormatter()
export class OrderProductFormatter implements Slick.Formatter {
format(ctx: Slick.FormatterContext) {
let options:string = '';
(ctx.value as number[]).forEach(value => {
var product = ProductRow.getLookup().itemById[value];
options += Q.format('<option value="{0}">{1}</option>', value, product.ProductName);
});
return '<select>' + options + '</select>';
}
}
} Don't forgot to run T4 template if you are using the older .net framwork version. Step 3Add using Serenity.ComponentModel;
using System;
using System.Collections.Generic;
namespace StartSharp1.Northwind.Columns
{
[ColumnsScript("Northwind.Order")]
[BasedOnRow(typeof(Entities.OrderRow), CheckNames = true)]
public class OrderColumns
{
[EditLink, AlignRight, SortOrder(1, descending: true), Width(70)]
public String OrderID { get; set; }
....
[OrderProductFormatter]
public List<Int32> ProductList { get; set; }
}
} If you got everything right, you will see the final result as expected. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
i have users row and each user have more than 1 department so the relation between them is many to many
i want to add column to user grid as a drop down list contain all user's departments
how can i do that ?
Beta Was this translation helpful? Give feedback.
All reactions