Tabler Datagrid#

class Datagrid(*items: Union[DatagridItem, Tuple[str, str], Tuple[str, str, Dict[str, Any]]], **kwargs)[source]#

Bases: Block

This widget implements a Tabler Data grid It contains DatagridItem objects.

Examples

Add DatagridItem objects to this in one of these ways:

As constructor arguments:

>>> item1 = DatagridItem(title='foo', content='bar', url="https://example.com")
>>> item2 = DatagridItem(title='baz', content='barney')
>>> item3 = ['foo', 'bar']
>>> grid = Datagrid(item1, item2, item3)

By using add_block with a DatagridItem:

>>> grid = Datagrid(item1, item2, item3)
>>> grid.add_block(DatagridItem(title='foo', content='bar'))

By using add_item:

>>> grid = Datagrid(item1, item2, item3)
>>> grid.add_item('foo', 'bar')
Parameters:

*items – a list of datagrid-item definitions or DatagridItem objects.

add_item(title: str, content: Union[str, Block, List[Union[str, Block]]], url: Optional[str] = None, **kwargs) None[source]#

Add a DatagridItem to our block contents, with datagrid-title of title and datagrid.

Examples

Start with our grid:

>>> dg = DataGrid()

Add a simple key/value:

>>> dg.add_item('Version', '1.2.3')

Add a block as the value, and wrap it in a wildewdigets.Link:

>>> dg.add_item(
    'Gravatar',
    Image(src=static('myapp/images/gravatar.png'), alt='MyGravatar'),
    url='https://www.google.com'
)

Add a list of blocks as the value:

>>> dg.add_item(
    'Contributors',
    [
        ImageLink(
            src=static('myapp/images/fred-gravatar.png',
            alt='Fred'
            url='https://www.fred.com'
        ),
        ImageLink(
            src=static('myapp/images/barney-gravatar.png',
            alt='Barney'
            url='https://www.barney.com'
        )
    ],
    css_class='d-flex flex-row'
)

Note

To add a DatagridItem directly, use add_block.

Keyword Arguments:
  • title – the datagrid-title of the datagrid-item

  • content – the datagrid-content of the datagrid-item

  • url – URL to use to turn content into a hyperlink

block: str = 'datagrid'#

block is the official wildewidgets name of the block; it can’t be changed by constructor kwargs

items: List[Union[DatagridItem, Tuple[str, str], Tuple[str, str, Dict[str, Any]]]] = []#

a list of datagrid-items to add to our content

class DatagridItem(*blocks, title: Optional[str] = None, url: Optional[str] = None, **kwargs)[source]#

Bases: Block

This widget implements a Tabler datagrid-item It should be used with Datagrid.

Note

Unlike wildewidgets.widgets.base.Block, DatagridItem requires either contents to be set, or the block contents to be provided as positional arguments.

Keyword Arguments:
  • title – the datagrid-title of the datagrid-item

  • url – URL to use to turn content into a hyperlink

Raises:
  • ValueError – either the title was empty, or no contents were provided

  • ImproperlyConfiguredurl was set, and there is more than one block in contents

add_blocks() None[source]#

Add our content.

If url is set, and there is only one block in contents, wrap that block in a wildewidgets.Link.

Raises:

ImproperlyConfiguredurl was set, and there is more than one block in contents

block: str = 'datagrid-item'#

block is the official wildewidgets name of the block; it can’t be changed by constructor kwargs

title: Optional[str] = None#

the datagrid-title of the datagrid-item

url: Optional[str] = None#

a URL to use to turn our contents into a hyperlink