Tabler Datagrid#

class Datagrid(*items: wildewidgets.widgets.datagrid.DatagridItem | tuple[str, str] | tuple[str, str, dict[str, Any]], **kwargs: Any)[source]#

Bases: Block

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

:param *:py:class:DatagridItem objects.:

add_item(title: str, content: str | wildewidgets.widgets.base.Block | list[str | wildewidgets.widgets.base.Block], url: str | None = None, **kwargs: Any) 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

  • **kwargs – additional keyword arguments passed to the DatagridItem constructor

block: str = 'datagrid'#

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

items: list[DatagridItemDef] = []#

a list of datagrid-items to add to our content

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

Bases: Block

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.

Examples

Create a DatagridItem with a title and content:

from wildewidgets import DatagridItem, Datagrid

item = DatagridItem(
    "This is the content of the item.",
    title="My Item",
    url="https://example.com"
)

grid = Datagrid(item)

# or

grid = Datagrid()
grid.add_item(item)
Parameters:

*blocks – strings or wildewidgets.widgets.base.Block objects to add to our datagrid-item. If contents is not set, these blocks will be used as the contents of the datagrid-item.

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: str | None = None#

the datagrid-title of the datagrid-item

url: str | None = None#

a URL to use to turn our contents into a hyperlink