Name | Surname | Age | Birthday | Employed |
---|---|---|---|---|
Joe | Crosswave | 36 | 1/5/1988 | False |
Cody | Jurut | 54 | 8/11/1970 | False |
Leena | Laurent | 24 | 7/1/2000 | False |
Diandra | Mizner | 25 | 8/20/1999 | False |
Pete | Cassel | 27 | 3/13/1997 | False |
N. Surname | Age | Birthday | Employed |
---|---|---|---|
J. Crosswave | 36 | 1/5/1988 | False |
M. Lisel | 46 | 5/6/1978 | |
H. Crux | 34 | 11/19/1990 | True |
C. Jurut | 54 | 8/11/1970 | False |
S. Scranton | 39 | 10/10/1985 | |
L. Laurent | 24 | 7/1/2000 | False |
O. Cosmides | 58 | 4/17/1966 | True |
D. Mizner | 25 | 8/20/1999 | False |
P. Cassel | 27 | 3/13/1997 | False |
N. Tremblay | 36 | 1/5/1988 | True |
@model IQueryable<Person>
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("Name");
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");
})
.UsingProcessor(new NotWorkingPersonFilter())
)
@model IQueryable<Person>
@(Html
.Grid(Model)
.Build(columns =>
{
columns.Add(model => model.Name).Titled("N. 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");
})
.UsingProcessor(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/sorting in a custom way
}
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 in a custom way
}
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
});
}
}