Copy grid Column to clipboard programmatically

Hi, on the attached razor page, i want to be able to be able to Copy the "MyDetails" column to clipboard programmatically. i am using the function below but it copies the whole grid row.

  public void OnContextMenuClick(ContextMenuClickEventArgs<Order> args)   {

   if (args.Item.Id == "copy-column-mydetails")

        {  this.DefaultGrid.Copy(false); }

    }


please note that i want to have the following settings enabled:

GridSelectionSettings Type="Syncfusion.Blazor.Grids.SelectionType.Multiple" CheckboxOnly="true" PersistSelection="true"></GridSelectionSettings>


Can you please help?

thanks 


Attachment: Test2_razor_page_2988d01.zip

8 Replies

SP Sarveswaran Palani Syncfusion Team August 29, 2022 04:17 PM UTC

Hi Dan,


Greetings from Syncfusion support.


We have analyzed your query and suspect that you want to copy specific column not an entire row. So, we created the sample based on your requirement and enabling selection mode as cell type to copy the specific cell to the clipboard. Kindly refer the attached sample for your reference.


Please get back to us if you have any further queries.


Regards,

Sarveswaran PK


Attachment: SfGridCopy2Clipboard_789b7ac7.zip


DA DAN August 30, 2022 06:39 AM UTC

hi,

thanks for the response.

yes, correct-we would like to copy a specific column but programmatically without having to select the specific column first BUT:

we would like to copy without having to select it first. so the copy functions will always copy a specific column.

e.g: this.DefaultGrid.Copy(column-with-name=MyDetails)

the code you sent be below ,we have first to find and click the column we like, and then we must copy.

We would like to do it, without setting enabling selection mode as cell type. is that also possible?

*************

public void Copy()

{

this.DefaultGrid.Copy();

}




MS Monisha Saravanan Syncfusion Team August 31, 2022 12:07 PM UTC

Hi DAN,


Thanks for the update.


Query: “we would like to copy without having to select it first. so the copy functions will always copy a specific column.”


We can select the cell programmatically before calling copy method by using SelectCellAsync. Kindly check the attached code snippet for your reference.


public async Task Copy()

    {

        await DefaultGrid.SelectCellAsync((2,2));

        this.DefaultGrid.Copy();

    }

 



Reference: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_SelectCellAsync_System_ValueTuple_System_Int32_System_Int32__System_Nullable_System_Boolean__



Query: “We would like to do it, without setting enabling selection mode as cell type. is that also possible?”


No it is not possible to select and copy an cell without enabling selection mode as cell type.


Please let us know if you have any concerns.


Regards,

Monisha

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



DA DAN August 31, 2022 03:42 PM UTC

Is it possible on your code above to programmatically enabling selection mode as cell type

Copy 

Then revert grid back to row?





KG Keerthana Ganesan Syncfusion Team September 1, 2022 03:49 PM UTC

Hi DAN,

Welcome from Syncfusion support.

Query: Programmatically Enabling selection mode as cell type


we can enable selection mode as a cell programmatically by getting an instance from the grid and assigning grid cell selection mode to the grid instance. Kindly refer to the attached code snippet for your reference.

public void Copy()

    {

        DefaultGrid.SelectionSettings.Mode = Syncfusion.Blazor.Grids.SelectionMode.Cell;

        this.DefaultGrid.Copy();

    }


Kindly get back to us if you have any further queries.

Regards,

Keerthana.



DA DAN September 2, 2022 07:35 AM UTC

 please see code below. it still does not work when trying to set mode to cell and then copying programmatically.

it copies the whole row.

can you please provide a working code/sample?

    if (args.Item.Id == "COPY-BENEFICIARY-LATIN")

        {

            DoCell();

            StateHasChanged();


           await this.GridnameVisitActivities.SelectCellAsync( (2, 8));

           StateHasChanged();

              await this.GridnameVisitActivities.CopyAsync(false);

            DoRow();

        }

    }


    public void DoCell()

    {

         GridnameVisitActivities.SelectionSettings.Mode = Syncfusion.Blazor.Grids.SelectionMode.Cell;

    }

      public void DoRow()

    {

       GridnameVisitActivities.SelectionSettings.Mode = Syncfusion.Blazor.Grids.SelectionMode.Row;

    }




KG Keerthana Ganesan Syncfusion Team September 5, 2022 03:42 PM UTC

Hi DAN,


Sorry for the inconvenience.


We are currently Validating the reported query at our end, and we will update the further details within two days(Sept7, 2022). Until then we appreciate your patience.


Regards,

Keerthana.



KG Keerthana Ganesan Syncfusion Team September 12, 2022 06:10 PM UTC

Hi DAN,

Sorry for the inconvenience caused.

Query: Copying cell when trying to set the mode to cell and the copying programmatically it copies the whole row.

We suggest to you refresh the Grid before enabling the selection mode. Kindly refer to the attached code snippet for your reference.

 

<SfGrid @ref="DefaultGrid" DataSource="@Orders">

     <GridSelectionSettings  Mode="@rowCellSelect" Type="Syncfusion.Blazor.Grids.SelectionType.Multiple"></GridSelectionSettings>

</
SfGrid>
@code{

private SfGrid<Order> DefaultGrid;

public List<Order> Orders { get; set; }

public SelectionMode rowCellSelect=SelectionMode.Both;

public void RowSelection()

    {

        DefaultGrid.Refresh();

        rowCellSelect = SelectionMode.Row;

 

    }

 

    public void CellSelection()

    {

        DefaultGrid.Refresh();

        rowCellSelect = SelectionMode.Cell;

 

    }
}


Kindly get back to us if you have any further queries.

Regards,

Keerthana.


Loader.
Up arrow icon