Columns
The columns option in the initialisation parameter allows you to define details about the way individual columns behave. For a full list of column options that can be set, please see the related parameters below.
Note that if you use columns to define your columns, you must have an entry in the array for every single column that you have in your table (these can be null if you don't wish to specify any options).
Configure columns:
@(Html.DataTable<Person>()
.Columns(c =>
{
c.Field(f => f.Id).Visible(false);
c.Field(f => f.Name).Title("Name");
c.Field(f => f.Age).Width("5%");
c.Field(f => f.Title);
})
...
Field¶
Make a column with defined type properties.
Title¶
Set column header. Default is property name.
Or useDisplayAttribute
for properties.
Name¶
Set a descriptive name for a column.
Visible¶
Set column visible or hidden, default is true.
Orderable¶
Set column orderable or not, default is true.
Searchable¶
Set column searchable or not, default is true.
Width¶
This parameter can be used to define the width of a column, and may take any CSS value (10%, 3em, 20px etc).
ClassName¶
DefaultContent¶
Set default value for null data.
DisplayFormat¶
Customize datetime format with Moment.js expression.
Or useDisplayFormatAttribute
for properties. (needed also moment.js)
Template¶
Customize column template using "data" for comparison.
.Template("(data === true) ? '<span class=\"bi bi-bookmark-check-fill\"></span>' : '<span class=\"bi bi-bookmark-x\"></span>'");
ContentPadding¶
Add padding to the text content used when calculating the optimal width for a table.
CreatedCell¶
Cell created callback to allow DOM manipulation.
Footer¶
Type¶
Set the column type - used for filtering and sorting string processing.