Read only grid without paging
With all-properties="true" all data item properties are rendered but the principal key. Principal key is auto-detected when it is called Id, otherwise it must be declared with the key tag attribute.
Some of the properties may be removed by adding a column definition like:
<column asp-for="Products.Data.Element().TypeId" remove="true"/>
inside the grid tag helper.
Column definitions without remove="true" add new columns or modify the default settings of inferred columns.Thus if for instance you want to render also the principal key, just add a column definition for it.
Without all-properties="true", the grid renders just properties having an explicit column definition.
Name | Price | Cur | Av | |
---|---|---|---|---|
16G Tablet | 400.00 | $ | ||
1T High speed | 120.00 | € | ||
1T SSD | 200.00 | € | ||
3D Glasses | 400.00 | $ | ||
color laser printer | 400.00 | $ | ||
ink jet printer | 100.00 | $ | ||
laptop | 1200.00 | € |
<grid asp-for="Products.Data" type="Immediate" all-properties="true" mvc-controller="typeof(LiveExamples.Controllers.GridsController)" row-id="readonly-example" operations="user => Functionalities.ReadOnly | Functionalities.ShowDetail" class="table table-condensed table-bordered"/>
/* DetailWidthsAsString in ColumnLayout specifies percentage width for different device screen widths, while WidthsAsString percentage width when shown in-line within a collection control. Oder specify the order columns are rendered. Higher Order come first. All setting, included Display/Name may be overriden by providing a column definition TagHelper within the control definition. */ public class SimpleProductViewModel { public int? Id { get; set; } [MaxLength(128)] [ColumnLayout(DetailWidthsAsString = "100 50")] [Required] [Display(Name = "Name", Order = 400)] public string Name { get; set; } [ColumnLayout(DetailWidthsAsString = "60 30")] [Display(Name = "Price", Order = 300)] public decimal Price { get; set; } [Display(Name = "Cur", Order = 280)] [ColumnLayout(WidthsAsString = "10", DetailWidthsAsString = "40 20")] public Currency ChosenCurrency { get; set; } [ColumnLayout(DetailWidthsAsString = "20")] [Display(Name = "Av", Order = 230)] public bool Available { get; set; } } public class SimpleProductViewModelDetail: SimpleProductViewModel { [MaxLength(256)] [Display(Name = "Description", Order = 100)] [ColumnLayout(DetailWidthsAsString = "80")] [DisplayFormat(NullDisplayText = "no description available")] public string Description { get; set; } }
public async Task<IActionResult> ReadonlyServer() { var model = new SimpleProductlistViewModel { Products = await Repository.GetPage<SimpleProductViewModel>( null, q => q.OrderBy(m => m.Name), 1, 20) }; return View(model); }