N. Surname | Surname | Age | Birthday | Employed |
---|---|---|---|---|
J. Crosswave | Crosswave | 32 | 1/5/1992 | False |
C. Jurut | Jurut | 50 | 8/11/1974 | False |
L. Laurent | Laurent | 20 | 7/1/2004 | False |
D. Mizner | Mizner | 21 | 8/20/2003 | False |
P. Cassel | Cassel | 23 | 3/13/2001 | False |
@model IQueryable<Person>
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("N. Surname");
columns.Add(model => model.Surname).Titled("Surname");
columns.Add(model => model.Age).Titled("Age");
columns.Add(model => model.Birthday).Titled("Birthday").Formatted("{0:d}");
columns.Add(model => model.IsWorking).Titled("Employed");
})
.Using(new NotWorkingPersonFilter())
.Using(new ShortNameProcessor())
)
public class NotWorkingPersonFilter : IGridProcessor<Person>
{
public GridProcessorType ProcessorType { get; set; }
public NotWorkingPersonFilter()
{
ProcessorType = GridProcessorType.Pre;
// Executed on all the data, mainly for filtering or sorting data.
}
public IQueryable<Person> Process(IQueryable<Person> items)
{
return items.Where(item => item.IsWorking == false);
}
}
public class ShortNameProcessor : IGridProcessor<Person>
{
public GridProcessorType ProcessorType { get; set; }
public ShortNameProcessor()
{
ProcessorType = GridProcessorType.Post;
// Executed after data is filtered and sorted, mainly for paging or mutating data.
}
public IQueryable<Person> Process(IQueryable<Person> items)
{
return items.Select(person => new Person
{
Id = person.Id,
Name = person.Name.Substring(0, 1) + ". " + person.Surname,
Surname = person.Surname,
Age = person.Age,
Birthday = person.Birthday,
IsWorking = person.IsWorking,
MaritalStatus = person.MaritalStatus,
Children = person.Children
});
}
}