HI,
I need to use multiple columns as primary key in SfGrid. However, when IsPrimaryKey=true is set for multiple columns, only first declared column is used as primary key. Is it possible to use composite/multi-column key?
This updates all rows in the grid when only one is edited.
<GridColumns>
<GridColumn Field="PatientId" HeaderText="" IsPrimaryKey="true" Visible="true" Width="25"></GridColumn>
<GridColumn Field="LineNo" HeaderText="" Width="25" IsPrimaryKey="true" Visible="true"></GridColumn>
<GridColumn Field="ProblemStatus" HeaderText="" Width="25"></GridColumn>
<GridColumn Field="ProblemDescr" HeaderText="Description" TextAlign="TextAlign.Left" Width="120" ></GridColumn>
<GridColumn Field="Diagnosis" HeaderText="Diagnosis" TextAlign="TextAlign.Left" Width="120"></GridColumn>
<GridColumn Field="OnsetDtStr" HeaderText="OnSet Date" Format="C2" TextAlign="TextAlign.Right" Width="60"></GridColumn>
</GridColumns>
However, when Field="LineNo" is defined first, it takes lineNO as primary key and updates only one , desired, line.
<GridColumns>
<GridColumn Field="LineNo" HeaderText="" Width="25" IsPrimaryKey="true" Visible="true"></GridColumn>
<GridColumn Field="PatientId" HeaderText="" IsPrimaryKey="true" Visible="true" Width="25"></GridColumn>
<GridColumn Field="ProblemStatus" HeaderText="" Width="25"></GridColumn>
<GridColumn Field="ProblemDescr" HeaderText="Description" TextAlign="TextAlign.Left" Width="120" ></GridColumn>
<GridColumn Field="Diagnosis" HeaderText="Diagnosis" TextAlign="TextAlign.Left" Width="120"></GridColumn>
<GridColumn Field="OnsetDtStr" HeaderText="OnSet Date" Format="C2" TextAlign="TextAlign.Right" Width="60"></GridColumn>
</GridColumns>
This is an issue when there are rows 1 to 4 for more than one patient.
Patient1000 lineNo1
Patient1000 lineNo2
Patient5555 lineNo1
Patient5555 lineNo2
In this case if PatientID is defined first, all lines for that patientID is updated when one line is edited. If LineNo is defined first, that LineNo is updated for all patientId when one line is edited.
I can create a dummy field in the underlying datasource and use that as primary key but it seems cumbersome. I was wondering if there is a way to define it in the grid.
Thank you for your help in advance.
Harshad
Hi Harshad,
Currently we don’t have support for multiple primary key columns .But We have considered it as an improvement and logged a task “Provide multiple primary key column support in Grid”. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. And this improvement will be included in any of our upcoming releases.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
https://www.syncfusion.com/feedback/13521/provide-multiple-primary-key-column-support-in-grid
You
can also communicate with us regarding the open feature any time using our
above feedback report page. We do not have immediate plan to implement this
feature and it will be included in any of our upcoming releases. So that we
will prioritize the improvement for every release based on demands.You can
communicate with us regarding the open features at any time using the above
Feature Report page.
Alternatively, we suggest sending the value
of another primary key column using additional parameters. Please refer to the
documentation below for your reference.
|
Index.Razor <GridEditSettings AllowEditing="true" AllowDeleting="true"></GridEditSettings> <GridEvents RowEdited="RowEditedHandler" TValue="Order"></GridEvents> <SfDataManager Adaptor="Adaptors.CustomAdaptor"> <CustomAdaptorComponent Query="Qry"></CustomAdaptorComponent> </SfDataManager> <GridPageSettings PageSize="8"></GridPageSettings> <GridColumns> <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn> <GridColumn Field=@nameof(Order.OrderID1) HeaderText="Order ID1" TextAlign="@TextAlign.Center" Width="140"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" TextAlign="@TextAlign.Center" Width="140"></GridColumn> </GridColumns> </SfGrid>
@code{ public static List<Order> Orders { get; set; } public Query Qry { get; set; } = new Query().AddParams("id", 2).AddParams("str", "23");
public void RowEditedHandler(RowEditedEventArgs<Order> args) {
// Add the SecondPrimaryKey value based on the edited row Qry.AddParams("SecondPrimaryKey",”Value”); } { //here you can access the query property var Additionalvalue= Query.Queries.Params["SecondPrimaryKey"];
return value;
} |
Regards,
Prathap Senthil