sfgrid Display chip in column after selecting ContextMenu

I am using a sfgrid with drag and drop. The user can drag names from one sfgrid to another. I would then like the user to be able to right click and select "Primary Contact" in the contextmenu. This will then add a chip to the selected row to indicate primary contact. Only 1 row is allowed to be primary!

Can you assist please?

1 Reply 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team May 14, 2021 07:16 AM UTC

Hi Martin, 

Greetings from Syncfusion support. 

We suggest you to use the Column Template feature to achieve this requirement. You can render a SfChip inside column based on the PrimaryContactValues list populated inside ContextMenuItemClicked event handler.  
References : 

Please refer and use the codes below, 

 
<GridEvents ContextMenuItemClicked="ContextMenuItemClickedHandler" TValue="Order"></GridEvents>
 
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Width="120"> 
    <Template> 
        @{ 
            var employee = (context as Order); 
            <div class="template_checkbox"> 
                @if (PrimaryContactValues.Contains(employee.OrderID.ToString())) 
                { 
                <div> 
                    <SfChip> 
                        <ChipItems> 
                            <ChipItem Text="Primary Contact"></ChipItem> 
                        </ChipItems> 
                    </SfChip> 
 
                    @employee.OrderID 
                </div> 
                } 
                else 
                { 
                    @employee.OrderID; 
                } 
            </div> 
        } 
    </Template> 
</GridColumn> 

public List<string> PrimaryContactValues = new List<string>();public void ContextMenuItemClickedHandler(ContextMenuClickEventArgs<Order> args){    if(args.Item.Text == "Primary Contact")    {        PrimaryContactValues.Add(args.RowInfo.RowData.OrderID.ToString());    }}

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Marked as answer
Loader.
Up arrow icon