|
<SfGrid TValue="Order" ID="Grid" AllowGrouping="true" AllowFiltering="true" AllowPaging="true"
Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })">
<GridGroupSettings Columns="@((new string[] { "OrderDate" }))"></GridGroupSettings>
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" Visible="false" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="ddd MMMM d yyyy" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>
</GridColumns>
</SfGrid>
@code{
public static List<Order> Orders { get; set; }
static int IdValue { get; set; } = 2000;
static List<Order> newData = new List<Order>() {
new Order() { OrderID = IdValue++, OrderDate = DateTime.Now.AddDays(1) },
new Order() { OrderID = IdValue++, OrderDate = DateTime.Now.AddDays(1) },
new Order() { OrderID = IdValue++, OrderDate = DateTime.Now.AddDays(2) }
}; //added primary key value and data value alone. Since primary key value is required for editing.
. . .
// Implementing custom adaptor by extending the DataAdaptor class
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<Order> DataSource = Orders;
. . .
int count = DataSource.Cast<Order>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = DataOperations.PerformTake(DataSource, dm.Take);
}
DataResult DataObject = new DataResult();
if (dm.Group != null)
{
DataSource = DataSource.Concat(newData); //added new empty data(only primary key value and data value present) while grouping
IEnumerable ResultData = DataSource.ToList();
// Grouping
foreach (var group in dm.Group)
{
ResultData = DataUtil.Group<Order>(ResultData, group, dm.Aggregates, 0, dm.GroupByFormatter);
}
DataObject.Result = ResultData;
DataObject.Count = count;
return dm.RequiresCounts ? DataObject : (object)ResultData;
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
}
|
|
|
An addendum to my last reply, Additionally, the grid event that I currently have the AddEmptyEntries bound to is not an ideal one, as there are several operations which cause the empty entries to disappear until the ondatabound event gets called again. Is there a different event or state that I can bind this function to? I just want the empty entries to be populated in the grid right before the week renders, but after the data has been retrieved, so that I know what days to add empty entries on.
|
// Implementing custom adaptor by extending the DataAdaptor class
public class CustomAdaptor : DataAdaptor
{
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<Order> DataSource = Orders;
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
if (dm.Group != null)
{
DataSource = DataSource.Concat(newData); //add the empty data here instead of adding in dm.Group
}
// Sorting
DataSource = DataOperations.PerformSorting(DataSource, dm.Sorted);
}
. . .
DataResult DataObject = new DataResult();
if (dm.Group != null)
{
//DataSource = DataSource.Concat(newData); //remove this line from here
IEnumerable ResultData = DataSource.ToList();
// Grouping
foreach (var group in dm.Group)
{
ResultData = DataUtil.Group<Order>(ResultData, group, dm.Aggregates, 0, dm.GroupByFormatter);
}
DataObject.Result = ResultData;
DataObject.Count = count;
return dm.RequiresCounts ? DataObject : (object)ResultData;
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
} |
|
|