How to disable Blazor ListView Item

Answer:

We can be achieved this in two ways. We can use the Enabled field within dataSource to enable and disable the items in ListView.

Else, with the help of a button click, we can achieve this by passing the required list item’s ID to the DisableItem method.

Refer to the code snippet.

public async Task DisableList()

{

DataModel data = new DataModel();

data.Id = "list-06";

await this.List.DisableItem(data);

}


Find the sample to disable Blazor ListView Item from here.


2 Replies

RS Robin Szemeti February 15, 2024 09:58 AM UTC

I think you'll find the code sample incorrect and the field is "Enable" in the code  not "Enabled"



PM Prasanth Madhaiyan Syncfusion Team February 16, 2024 09:30 AM UTC

Hi Robin,


Greetings from Syncfusion support.


Based on the shared details, we would like to let you know that you can choose any convenient name for the 'ListView' component's 'Enabled' field value. It will not cause any issues in the 'ListView' component. For example, we have mapped the name 'ListViewEnabled' for the 'Enabled' field value, and it is working as expected without any issues.


Refer to the below code snippets.


<SfButton id="disable" Content="Disable Item" OnClick="DisableList"></SfButton>

<SfListView DataSource="@Data" @ref="List" TValue="DataModel">

    <ListViewFieldSettings TValue="DataModel" Id="Id" Text="Text" Enabled="ListViewEnabled"></ListViewFieldSettings>

</SfListView>

 

@code

{

    SfListView<DataModel> List;

    private DataModel[] Data = {

            new DataModel { Text = "ArtWork", Id = "list-01",ListViewEnabled=true },

            new DataModel { Text = "Abstract", Id = "list-02",ListViewEnabled=true },

            new DataModel { Text = "Modern Painting", Id = "list-03", ListViewEnabled=false },

            new DataModel { Text = "Ceramics", Id = "list-04",ListViewEnabled=true },

            new DataModel { Text = "Animation Art", Id = "list-05",ListViewEnabled=true },

            new DataModel { Text = "Oil Painting", Id = "list-06",ListViewEnabled=true }

    };

    class DataModel

    {

        public string Text { get; set; }

        public string Id { get; set; }

        public bool ListViewEnabled { get; set; }

    }

 

   

}



For your reference, we have attached the sample and screenshot.


Sample: https://blazorplayground.syncfusion.com/LtVTthiRAKdEjomt


Screenshot:



Check out the attached sample and let us know if you need any further assistance.


Regards,

Prasanth Madhaiyan.


Loader.
Up arrow icon