How to make read only grid cells in Blazor

Hi All,

I am generating the grid header dynamically from database. But i need to make read one column. Currently it is editable. Could you please give me syntax for this ?

public void QueryCellInfoHandler(Syncfusion.Blazor.Grids.QueryCellInfoEventArgs<Inspection> args)
    {
        if (args.Data.RecType.Trim() == "HEAD")
        {
            args.Cell.AddClass(new string[] { "Head1" });

          // Need the syntax for making read only cell

        }
    }

5 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team December 1, 2020 08:00 AM UTC

Hi chandradev, 

Greetings from Syncfusion support. 

You can make a GridColumn as read only by disabling the AllowEditing property of particular GridColumn. Please refer the below documentation for more details regarding preventing the editing for the particular column in Grid.  
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Marked as answer

CH chandradev December 1, 2020 09:07 AM UTC

Thanks for reply. I need for row disable syntax. 


CH chandradev December 1, 2020 02:18 PM UTC

<SfGrid DataSource="@inspectGrid"
        GridLines="GridLine.Both"
        Toolbar="@(new List<string>() {"Update", "Cancel"})">

    <GridEvents OnBatchSave="BatchSaveHandler" RowSelecting="RowSelectingHandler" 
                CellSelecting="CellSelectingHandler"  RowSelected="RowSelectedHandler"
                QueryCellInfo="QueryCellInfoHandler"
                TValue="Inspection" />

    <GridEditSettings AllowAdding="true"
                      AllowDeleting="true"
                      AllowEditing="true"
                      Mode="EditMode.Batch" />


    <GridColumns>
        <GridColumn Field=@nameof(Inspection.PriInspectionId) IsPrimaryKey="true" AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn1) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn2) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn3) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn4) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn5) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn6) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn7) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn8) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.OrderNo) Visible="false" AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.RecType) Visible="false" />
        <GridColumn Field=@nameof(Inspection.MediaFileUrl) AutoFit="true" />
    </GridColumns>
</SfGrid>

<style>
    .e-grid .e-gridheader .e-columnheader {
        display: none;
    }

    .e-grid .e-gridcontent .e-rowcell.Head1 {
        background-color: lightskyblue;
        font-weight: bold;
    }
</style>

public void RowSelectingHandler(RowSelectingEventArgs<Inspection> args)
    {
        if (args.Data.RecType.Trim() == "HEAD") //we ahve prevented the row selection for order id --1004 
        {
            args.Cancel = true;

        }
    }

    public void CellSelectingHandler(CellSelectingEventArgs<Inspection> args)
    {
        args.Cancel = true;
    }

    public void RowSelectedHandler(RowSelectEventArgs<Inspection> args)
    {
        args.Cancel = true;
    }


My requirement is make the one complete row as read only or disable editable row, But i m using Mode="EditMode.Batch" in Grid. I tried the above syntax. It is not working. 


CH chandradev replied to chandradev December 1, 2020 04:34 PM UTC

<SfGrid DataSource="@inspectGrid"
        GridLines="GridLine.Both"
        Toolbar="@(new List<string>() {"Update", "Cancel"})">

    <GridEvents OnBatchSave="BatchSaveHandler" RowSelecting="RowSelectingHandler" 
                CellSelecting="CellSelectingHandler"  RowSelected="RowSelectedHandler"
                QueryCellInfo="QueryCellInfoHandler"
                TValue="Inspection" />

    <GridEditSettings AllowAdding="true"
                      AllowDeleting="true"
                      AllowEditing="true"
                      Mode="EditMode.Batch" />


    <GridColumns>
        <GridColumn Field=@nameof(Inspection.PriInspectionId) IsPrimaryKey="true" AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn1) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn2) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn3) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn4) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn5) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn6) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn7) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.Icolumn8) AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.OrderNo) Visible="false" AutoFit="true" />
        <GridColumn Field=@nameof(Inspection.RecType) Visible="false" />
        <GridColumn Field=@nameof(Inspection.MediaFileUrl) AutoFit="true" />
    </GridColumns>
</SfGrid>

<style>
    .e-grid .e-gridheader .e-columnheader {
        display: none;
    }

    .e-grid .e-gridcontent .e-rowcell.Head1 {
        background-color: lightskyblue;
        font-weight: bold;
    }
</style>

public void RowSelectingHandler(RowSelectingEventArgs<Inspection> args)
    {
        if (args.Data.RecType.Trim() == "HEAD") //we ahve prevented the row selection for order id --1004 
        {
            args.Cancel = true;

        }
    }

    public void CellSelectingHandler(CellSelectingEventArgs<Inspection> args)
    {
        args.Cancel = true;
    }

    public void RowSelectedHandler(RowSelectEventArgs<Inspection> args)
    {
        args.Cancel = true;
    }


My requirement is make the one complete row as read only or disable editable row, But i m using Mode="EditMode.Batch" in Grid. I tried the above syntax. It is not working. 

I fixed the issue using css like this

 pointer-events: none;


RS Renjith Singh Rajendran Syncfusion Team December 2, 2020 10:31 AM UTC

Hi chandradev, 

Thanks for your update. 

We are glad to hear that you have achieved your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Loader.
Up arrow icon