ListGroup

in namespace DotVVM.Framework.Controls.Bootstrap4

Renders a Bootstrap list group of items, links or buttons.

Usage & Scenarios

Renders a Bootstrap list group of items, links or buttons.

https://getbootstrap.com/docs/4.3/components/list-group/

Sample 1: Basic ListGroup

Each item inside the ListGroup is represented by the ListGroupItem control.

Place the items inside the ListGroup.

<bs:ListGroup>
  <bs:ListGroupItem Text="{value: Text}" />
  <bs:ListGroupItem Text="Item 2" />
  <bs:ListGroupItem Text="Item 3" />
  <bs:ListGroupItem>
    <h3>Custom content</h3>
    <p>Custom list item content</p>
  </bs:ListGroupItem>
</bs:ListGroup>
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Text { get; set; } = "Data-bound text of the item.";
    }
}

Sample 2: ListGroup - Item types

The ListGroup control has the ItemType property which specified the type of list group items - Default, Link and Button.

<bs:ListGroup ItemType="Button">
  <bs:ListGroupItem Text="Item 1" />
  <bs:ListGroupItem Text="Item 2" Color="Primary" />
  <bs:ListGroupItem Text="Item 3" Color="Info" />
  <bs:ListGroupItem Text="{value: Text}" Color="Success" />
  <bs:ListGroupItem Text="Item 5" Color="Warning" />
  <bs:ListGroupItem Text="Item 6" Color="Danger" />
</bs:ListGroup>
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Text { get; set; } = "This is sample text.";
    }
}

Sample 3: Data-binding

The DataSource property can be used to generate the items from an IEnumerable in the viewmodel.

Then you can use the following properties which tell the control what property of the collection item will be used:

  • TextBinding specifies the property of the collection elements to be used as list item text.
  • ColorBinding specifies the property of the collection elements to be used as list item color.
  • NavigateUrlBinding specifies the property of the collection elements to be used as list item link URL.
  • IsEnabledBinding specifies the property of the collection elements indicating whether the list item is enabled or not.
  • IsSelectedBinding specifies the property of the collection elements indicating whether the list item is active or not.
  • ClickBinding specifies a command in the viewmodel to be called when the list item is clicked.
<bs:ListGroup ItemType="Link" 
              DataSource="{value: LinksDataSet}" 
              IsEnabledBinding="{value: IsEnabled}" 
              IsSelectedBinding="{value: IsSelected}" 
              TextBinding="{value: Text}" 
              ColorBinding="{value: Color}" 
              NavigateUrlBinding="{value: NavigateUrl}" />
public class ViewModel : DotvvmViewModelBase
{
    public List<LinkItem> LinksDataSet => new List<LinkItem>()
    {
        new LinkItem() { IsEnabled = true, IsSelected = false, NavigateUrl = "https://www.google.com/", Text = "Google", Color = BootstrapColor.Info },
        new LinkItem() { IsEnabled = true, IsSelected = false, NavigateUrl = "http://www.w3schools.com/html/", Text = "W3Schools", Color = BootstrapColor.Success },
        new LinkItem() { IsEnabled = true, IsSelected = true, NavigateUrl = "https://www.microsoft.com/en-us/", Text = "Microsoft", Color = BootstrapColor.Warning },
        new LinkItem() { IsEnabled = false, IsSelected = false, NavigateUrl = "https://github.com/riganti/dotvvm", Text = "DotVVM Github", Color = BootstrapColor.Danger }
    };
    
}

public class LinkItem
{
    public string Text { get; set; }
    public string NavigateUrl { get; set; }
    public bool IsSelected { get; set; }
    public bool IsEnabled { get; set; }
    public BootstrapColor Color { get; set; }

}

Sample 4: Data-binding

The ClickBinding property can be used when the list group contains the buttons.

<bs:ListGroup ItemType="Button" 
              DataSource="{value: Values}" 
              TextBinding="{value: _this}" 
              ClickBinding="{command: _parent.Select(_this)}" />

Selected item: {{value: SelectedValue}}
using DotVVM.Framework.Controls.Bootstrap4;
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        public List<string> Values => new List<string>() { "one", "two", "three" };

        public string SelectedValue { get; set; }
        
        
        public void Select(string value)
        {
            SelectedValue = value;
        }
    }
    
}

Sample 5: Badges

The list items can contain Badge controls. USe the Badge inner element property to specify the badge contents.

<bs:ListGroup>
  <bs:ListGroupItem Text="{value: Text}">
    <Badge>
      <bs:Badge>10</bs:Badge>
    </Badge>
  </bs:ListGroupItem>
  <bs:ListGroupItem Text="Item 2">
    <Badge>
      <bs:Badge>2</bs:Badge>
    </Badge>
  </bs:ListGroupItem>
</bs:ListGroup>
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Text { get; set; } = "Data-bound text of the item.";
    }
}

Sample 6: Flush mode

The IsFlush property can be used to render the list group without borders to render the list group items edge-to-edge in a parent container.

Flush mode cannot be combined with horizontal ListGroup

<bs:ListGroup IsFlush="true">
  <bs:ListGroupItem Text="{value: Text}" />
  <bs:ListGroupItem Text="Item 2" />
  <bs:ListGroupItem Text="Item 3" />
  <bs:ListGroupItem Text="Item 4" />
</bs:ListGroup>
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Text { get; set; } = "Data-bound text of the item.";
    }
}

Sample 7: Type and responsibility

The Type property controls whether the ListGroup would be Horizontal or Vertical.

When using Horizontal ListGroup, than we can also use MaximumScreenSizeBeforeChangeToVertical to set when the ListGroup should change from Horizontal to Vertical.
If set to None than the ListGroup will never change to Vertical.

<bs:ListGroup Type="Horizontal" MaximumScreenSizeBeforeChangeToVertical="Medium" >
  <bs:ListGroupItem Text="{value: Text}" />
  <bs:ListGroupItem Text="Item 2" />
  <bs:ListGroupItem Text="Item 3" />
  <bs:ListGroupItem Text="Item 4" />
</bs:ListGroup>
using DotVVM.Framework.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DotvvmWeb.Views.Docs.Controls.bootstrap.ListGroup.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public string Text { get; set; } = "Data-bound text of the item.";
    }
}

Properties

Name Type Description Notes Default Value
property icon BadgeBinding Badge Gets or sets a binding which defines the contents of the badge that will be created in each item. Use this property in combination with the DataSource property.
attribute
inner element
static value
bindable
default
null
property icon ColorBinding IValueBinding Gets or sets a binding which defines color of each generated item. Use this property in combination with the DataSource property.
attribute
inner element
static value
bindable
default
null
property icon DataSource Object Gets or sets the source collection or a GridViewDataSet that contains data in the control.
attribute
inner element
static value
bindable
default
null
property icon IsEnabledBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is disabled or not.
attribute
inner element
static value
bindable
default
null
property icon IsFlush Boolean Gets or sets whether to remove some borders and rounded corners to render list group items edge-to-edge in a parent container.
attribute
inner element
static value
bindable
default
False
property icon IsSelectedBinding IValueBinding Gets or sets a value binding that points to a property indicating whether the item is selected or not.
attribute
inner element
static value
bindable
default
null
property icon Items List<IListGroupItem> Gets or sets a collection of items that is used when no DataSource is set.
attribute
inner element
static value
bindable
default
null
property icon ItemsContentTemplate ITemplate Gets or sets the template for contents of the generated items when using the DataSource property.
attribute
inner element
static value
bindable
default
null
property icon ItemType ListGroupItemType Gets or sets the type of the items.
attribute
inner element
static value
bindable
default
Default
property icon MaximumScreenSizeBeforeChangeToVertical ResponsiveBreakpoints Gets or sets the maximum screen size before the ListGroup will change to vertical mode. If set to None than the ListGroup will never change to vertical.
attribute
inner element
static value
bindable
default
None
property icon NavigateUrlBinding IValueBinding Gets or sets the value binding that points to a property which will be navigated to when the item is clicked.
attribute
inner element
static value
bindable
default
null
property icon ScrollSpyEnabled Boolean
attribute
inner element
static value
bindable
default
False
property icon ScrollSpyOffset Int32
attribute
inner element
static value
bindable
default
10
property icon TextBinding IValueBinding Gets or sets the value binding that points to a property which will be used as the text of the item.
attribute
inner element
static value
bindable
default
null
property icon Type ListGroupType Gets or sets the type of ListGroup. e.g. Vertical, Horizontal
attribute
inner element
static value
bindable
default
Vertical

Events

Name Type Description
event icon ClickBinding ICommandBinding Gets or sets a binding which defines a click action for button items.

HTML produced by the control