<GridColumns>
<GridColumn Field=@nameof(TimeTransactionsDto.TranId) IsPrimaryKey="true" HeaderText="Id" TextAlign="TextAlign.Left" Edit="false"></GridColumn>
<GridColumn Field=@nameof(TimeTransactionsDto.SiteId) AllowEditing="false" HeaderText="SiteId" TextAlign="TextAlign.Left" Edit="false"></GridColumn>
<GridColumn Field=@nameof(TimeTransactionsDto.DateTimeWeek) HeaderText="Week" TextAlign="TextAlign.Left" Edit="false"></GridColumn>
...
</GridColumns>
|
public void ActionBeginHandler(ActionEventArgs<TimeTransactionsDto> args)
{
if (args.Type == "actionBegin")
if (args.Action == "edit")
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
args.Data.DateTime = args.Data.DateTime.Value.AddHours(-5); //based on your delay please set the value. Based on your delay(-4 or -5) please add the hours
var d = args.Data;
}
}
}
public class TimeTransactionsDto
{
public int TranId { get; set; }
...
public DateTime? DateTime { get; set; }
...
}
|
public override object Update(DataManager dm, object value, string keyField, string key)
{
var data = dto.Where(or => or.TranId == (value as TimeTransactionsDto).TranId && or.SiteId == (value as TimeTransactionsDto).SiteId).FirstOrDefault();
if (data != null)
{
data.TranId = (value as TimeTransactionsDto).TranId;
data.SiteId = (value as TimeTransactionsDto).SiteId;
data.DateTimeWeek = (value as TimeTransactionsDto).DateTimeWeek;
data.Activity = (value as TimeTransactionsDto).Activity;
data.DateTime = (value as TimeTransactionsDto).DateTime;
}
return value;
}
|
how to provide primary key for a column when the grid is being auto-generated and i can't manually declare/set using attribute of primarykey=true
Hi Muhammad,
Greetings from Syncfusion.
Query: “how to provide primary key for a column when the grid is being auto-generated and i can't manually declare/set using attribute of primarykey=true”
We recommend you to set the IsPrimaryKey property of the column by using OnDataBound event. The OnDataBound event will be triggered before data is bound to the Grid. So we can customize based on our requirement inside the event handler.
We have already documented this topic in this section. Kindly refer the mentioned thread and code snippet for further followups.
<GridEvents OnDataBound="DataBoundHandler" TValue="OrderData"></GridEvents> <GridEditSettings AllowEditing="true" AllowAdding="true" AllowDeleting="true"></GridEditSettings> </SfGrid>
@code { private SfGrid<OrderData> Grid; public List<OrderData> Orders { get; set; }
protected override void OnInitialized() { Orders = OrderData.GetAllRecords(); } public void DataBoundHandler(BeforeDataBoundArgs<OrderData> args) { Grid.Columns[0].IsPrimaryKey = true; } }
|
Kindly get back to us if you have further queries.
Regards,
Monisha