Skip to content

Extras

DataGrid

Bit.BlazorUI.ExtrasDataTableTreeGridTreeList

BitDataGrid displays an information-rich data table and gives people the tools to work through it: sorting, quick search and per-column filters, paging, grouping with aggregates, selection, inline editing, resizable/reorderable/frozen columns, master-detail and tree rows, keyboard cell navigation, row and column virtualization, and CSV/Excel export. Bind a list, an IQueryable executed at the source, or a callback for server-side paging or infinite scrolling. Use a data grid when information density is critical.

Localization & appearance

Translating the grid's texts and its values, the disabled grid, app-wide defaults through BitParams, the pager and toolbar layout, Style & Class with the CSS variables, and right-to-left grids.

Localization

Every string the grid renders or announces - pager, messages, placeholders, buttons, accessible names and live-region announcements - comes from Strings. Override what you need; the rest keeps its English default.

BitDataGridStrings holds 95 texts. The ones with a {0} are format strings whose placeholders must be kept (PagerRangeFormat takes the first row, the last row and the total). EmptyText and NoMatchesText default to BitStrings.Current, so an app that localizes BitStrings already has them. Hand the same instance to every grid of an app through BitParams (see Cascading parameters).

The column titles are yours: set Title in the user's language, since the default is the property name. Format writes numbers and dates in the current culture (the Preis column's C2 writes the page culture's currency), and a cell's values themselves can be translated with ValueText (see Value text).

1
Vintage Gadget 212
$171.75
131
2
Eco Notebook 554
$382.16
130
3
Classic Gadget 181
$813.02
269
4
Vintage Blender 267
$310.12
291
5
Vintage Jacket 234
$55.50
390
6
Smart Drone 229
$603.51
257
7
Eco Widget 428
$72.97
359
8
Pro Blender 549
$825.55
6
1–8 von 60
Seite 1 von 8

Disabled

Disabled keeps the data readable - a focused cell still moves and copies - but disables every control and gesture in the grid, which reports aria-disabled.

While disabled, the grid keeps showing its sort, filters, selection and page, but none of them can be changed from it: headers do not sort, filters, the search box, checkboxes and the pager are disabled, columns cannot be resized or moved, rows cannot be dragged, nothing opens for editing, and the row and cell events are not raised. Arrow keys still move between the cells and Ctrl/⌘+C still copies. A FilterTemplate gets the state as its context's Disabled, to disable its own control. The API methods are not blocked, so code can still sort, filter or page a disabled grid. The text color is --bit-DataGrid-disabled-color.


ID
Name
Category
Price
1
Vintage Gadget 212
Home
$171.75
2
Eco Notebook 554
Clothing
$382.16
3
Classic Gadget 181
Toys
$813.02
4
Vintage Blender 267
Electronics
$310.12
5
Vintage Jacket 234
Electronics
$55.50
6
Smart Drone 229
Electronics
$603.51
7
Eco Widget 428
Books
$72.97
8
Pro Blender 549
Electronics
$825.55
1–8 of 40
Page 1 of 5

Cascading parameters

BitParams carries a BitDataGridParams to every grid under it - the defaults an app wants everywhere, Strings included. Both grids here take row numbers, a filter row and pages of 5 from it; they are defaults, not overrides, so the second grid keeps the Striped it sets itself.

A value set on the params object applies wherever the grid does not set the parameter itself; one left null leaves the grid's own default. Put the BitParams high in the app - around the router in the layout - to make it app-wide. Since the grid is generic over its rows, only what does not depend on them can be shared: the look (Bordered, Striped, Hoverable, RowHeight, Height, Classes, Styles), the features (Filterable, Pageable, PageSize, Resizable, ShowSearchBox, the export buttons and their icons, ...), Strings, EmptyTemplate and LoadingTemplate. The data, the selectors, the selection, the templates typed over the row, the event callbacks, and the choices that belong to one data set - Editable, SelectionMode, RowReorderable, Virtualize, ToolbarTemplate, ExportFileName - stay on each grid.

1
1
Vintage Gadget 212
$171.75
2
2
Eco Notebook 554
$382.16
3
3
Classic Gadget 181
$813.02
4
4
Vintage Blender 267
$310.12
5
5
Vintage Jacket 234
$55.50
1–5 of 30
Page 1 of 6

1
1
Vintage Gadget 212
$171.75
2
2
Eco Notebook 554
$382.16
3
3
Classic Gadget 181
$813.02
4
4
Vintage Blender 267
$310.12
5
5
Vintage Jacket 234
$55.50
1–5 of 30
Page 1 of 6

Value text

ValueText sets the text a column's values are shown as - a translated or friendlier name for each member of an enum, a word for a boolean - without changing the data. It receives a non-null value of the bound property and returns its text, or null to keep the default: here four categories get a longer name and the others keep their own, and the Discontinued flag reads as a status.

The text is used wherever the grid shows the value: the cells (unless a Template draws them) and their tooltips, the group headers (group by Category or Status), a Min or Max aggregate, the options of an enum or boolean column's filter and inline editor, and, with an in-memory source, what the quick search and the text filter operators match - search for "garden". It is display only: CSV, Excel and the clipboard keep writing the value formatted by Format (give a column an ExportValue to export other text), sorting still orders the values themselves, and an IQueryable or OnRead source searches and filters the stored value, except that an IQueryable's quick search matches an enum column's members by their text.

Without ValueText an enum member is shown by the name of its [Display] attribute (translated when the attribute names a ResourceType), or else by its own name, and a Format writes the value instead (D for an enum's number). A new text - another mapping, or a new UI culture - reaches the cells, group headers and options on the next render; the search and the aggregates follow when the grid refreshes its view, which handing over another method does, while the same method returning other text needs RefreshAsync.

1
Vintage Gadget 212
Home & garden
In catalog
$171.75
2
Eco Notebook 554
Clothing
Discontinued
$382.16
3
Classic Gadget 181
Toys
In catalog
$813.02
4
Vintage Blender 267
Electronics & gadgets
Discontinued
$310.12
5
Vintage Jacket 234
Electronics & gadgets
Discontinued
$55.50
6
Smart Drone 229
Electronics & gadgets
In catalog
$603.51
7
Eco Widget 428
Books
In catalog
$72.97
8
Pro Blender 549
Electronics & gadgets
Discontinued
$825.55
1–8 of 60
Page 1 of 8

Pager & toolbar

PagerPlacement puts the pager below the rows (Bottom, the default), above them (Top) or both (TopAndBottom); any other BitPlacement value is Bottom. PageSizeOptions are the sizes the pager's dropdown offers (10, 20, 50 and 100 by default), and the PageSize in effect is added to them when it is not one of them - 15 joins 10, 25 and 50 here. The pager only renders while paging is active: Pageable is set and the rows are not grouped, a tree or infinitely scrolled. OnPageChange reports each new page.

ToolbarTemplate puts your own content at the start of the toolbar, before the built-in controls (Add row, the search box, Clear filters, the exports and Columns), and shows the toolbar on its own - here, buttons that move the pager and hide the header. A toolbar with nothing in it takes no room. Classes.Toolbar and Classes.Pager (and their Styles) style the two bars.

ShowHeader="false" hides the header rows - the column titles, the Group headers and the filter row - for a grid read as a plain list. Without headers there is nothing to click to sort, resize or reorder a column, so those are left to the API (Programmatic control).

1–15 of 120
Page 1 of 8
1
Vintage Gadget 212
Home
$171.75
2
Eco Notebook 554
Clothing
$382.16
3
Classic Gadget 181
Toys
$813.02
4
Vintage Blender 267
Electronics
$310.12
5
Vintage Jacket 234
Electronics
$55.50
6
Smart Drone 229
Electronics
$603.51
7
Eco Widget 428
Books
$72.97
8
Pro Blender 549
Electronics
$825.55
9
Deluxe Mug 514
Clothing
$615.44
10
Mini Jacket 367
Grocery
$585.87
11
Vintage Gadget 192
Home
$334.92
12
Mini Mug 788
Toys
$712.80
13
Classic Mug 124
Books
$267.79
14
Compact Gadget 195
Clothing
$325.60
15
Deluxe Speaker 932
Sports
$281.65
1–15 of 120
Page 1 of 8

Style & Class

Style and Class land on the root; Styles and Classes reach each part on its own - the toolbar, the header row and cells, the rows, a selected row, the cells, the footer, the pager and more.

The parts are Root, Toolbar, ColumnChooser, Viewport (the scrolling area), HeaderRow, HeaderCell, FilterRow, Row, SelectedRow, Cell, GroupRow, DetailRow, FooterRow, Pager, Empty, Loading and ReadError. A part's class comes before the per-row and per-column ones (RowClass, a column's HeaderClass and CellClass), which therefore win at equal weight; SelectedRow is added after Row. The classes land on elements the grid renders, so a page's isolated CSS reaches them through ::deep from a plain element of its own - the div around the first grid (see the stylesheet tab).

1
Vintage Gadget 212
$171.75
2
Eco Notebook 554
$382.16
3
Classic Gadget 181
$813.02
4
Vintage Blender 267
$310.12
5
Vintage Jacket 234
$55.50
1–5 of 20
Page 1 of 4


The grid also reads CSS variables. They inherit, so a value on :root or an ancestor restyles every grid below it, and one on Style restyles that grid - and any grid nested inside it, such as one in a detail row. Here: a compact, accent-colored grid. The variables restyle the defaults of the theme: the cell padding, font, header, stripe, hover, selected, editing, group, detail and footer colors, the accent of the sort arrows and checkboxes, the focus color and the tree and group indents.

1
1
Vintage Gadget 212
Home
$171.75
2
2
Eco Notebook 554
Clothing
$382.16
3
3
Classic Gadget 181
Toys
$813.02
4
4
Vintage Blender 267
Electronics
$310.12
5
5
Vintage Jacket 234
Electronics
$55.50
6
6
Smart Drone 229
Electronics
$603.51
7
7
Eco Widget 428
Books
$72.97
8
8
Pro Blender 549
Electronics
$825.55
9
9
Deluxe Mug 514
Clothing
$615.44
10
10
Mini Jacket 367
Grocery
$585.87
11
11
Vintage Gadget 192
Home
$334.92
12
12
Mini Mug 788
Toys
$712.80
13
13
Classic Mug 124
Books
$267.79
14
14
Compact Gadget 195
Clothing
$325.60
15
15
Deluxe Speaker 932
Sports
$281.65
16
16
Eco Widget 307
Grocery
$982.55
17
17
Mini Blender 740
Electronics
$597.20
18
18
Pro Blender 952
Sports
$132.04
19
19
Classic Drone 459
Electronics
$906.58
20
20
Mega Mug 839
Sports
$282.70

RTL

Dir="BitDir.Rtl" mirrors the grid: frozen columns, arrows and keyboard navigation follow the reading direction. Without it, the grid takes a cascaded BitDir, or else the page's direction.

In a right-to-left grid the start edge is the right: Frozen columns pin to the right and FrozenEnd ones to the left, Align's Start and End swap sides (Left and Right do not), and the horizontal arrow keys - cell navigation, a tree node's open and close, a resize handle - follow the reading direction. Pair it with translated Strings and column titles, as here; the category text comes from a Template, where ValueText would also translate the filter options, the group headers and the search.

1
قدیمی گجت 212
خانه
$171.75
131
2
اقتصادی دفترچه 554
پوشاک
$382.16
130
3
کلاسیک گجت 181
اسباب‌بازی
$813.02
269
4
قدیمی مخلوط‌کن 267
الکترونیک
$310.12
291
5
قدیمی ژاکت 234
الکترونیک
$55.50
390
6
هوشمند پهپاد 229
الکترونیک
$603.51
257
7
اقتصادی ویجت 428
کتاب
$72.97
359
8
حرفه‌ای مخلوط‌کن 549
الکترونیک
$825.55
6
1–8 از 60
صفحهٔ 1 از 8

Feedback

Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.