@inject OrderDataAccessLayer db
<EjsGrid @ref="Grid" DataSource="@Orders" AllowPaging="true">
...
</EjsGrid>
@code{
EjsGrid<Order> Grid { get; set; }
IQueryable<Order> Orders;
protected override void OnInitialized()
{
Orders = db.GetAllOrders();
}
}
[OrderDataAccessLayer.cs]
public class OrderDataAccessLayer
{
OrderContext db = new OrderContext();
//To Get all Orders details
public DbSet<Order> GetAllOrders()
{
try
{
return db.Orders;
}
catch
{
throw;
}
}
...
}
[OrderContext.cs]
public class OrderContext : DbContext
{
public virtual DbSet<Order> Orders { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\RenjithSinghRajendra\Downloads\EFGrid\EFGrid\EFGrid\App_Data\NORTHWND.MDF';Integrated Security=True;Connect Timeout=30");
}
}
}
|
<EjsGrid @ref="Grid" TValue="Order" AllowPaging="true">
<EjsDataManager Url="/api/Default" Adaptor="Adaptors.UrlAdaptor"></EjsDataManager>
...
</EjsGrid>
[DefaultController.cs]
[HttpPost]
[Route("api/[controller]")]
public object Post([FromBody]DataManagerRequest dm)
{
IQueryable<Order> DataSource = db.GetAllOrders();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = DataOperations.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Order>().Count();
if (dm.Skip != 0)
{
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
return new { result = DataSource, count = count };
}
|