NooBIT.DataTables provides functionality to process ajax requests from https://datatables.net javascript framework v1.10.x
Service | Status |
---|---|
AppVeyor |
Package | NuGet |
---|---|
NooBIT.DataTables | |
NooBIT.DataTables.AspNetCore.Mvc |
Implement your custom table like this:
public class EmployeeTable : DataTable<Employee>
{
public EmployeeTable(IQueryableService<Employee> queryableService) : base(queryableService)
{
}
}
You need some columnDefs for datatables options. You can override the default:
public class EmployeeTable : DataTable<Employee>
{
// [...]
protected override Column GetColumnTemplate(PropertyInfo x, int index)
{
return new Column(this)
{
Header = new Header {DisplayName = x.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ?? x.Name},
Name = x.Name,
Orderable = true,
Orders = new[]
{
new Column.Order
{
ColumnName = x.Name
}
},
Render = (o, item) => o,
Searchable = true,
Target = index
};
}
}
Or if you want complete control over column generation:
public class EmployeeTable : DataTable<Employee>
{
// [...]
protected override Column[] GetColumnsInternal() =>
typeof(Employee).GetProperties(BindingFlags.Instance | BindingFlags.Public)
.OrderBy(x => x.GetCustomAttribute<ColumnOrderAttribute>()?.Order ?? int.MaxValue)
.Select(GetColumnTemplate)
.ToArray();
}
TODO language documentation