cmxl / NooBIT.DataTables

.NET Library for https://datatables.net/ v1.10.x

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NooBIT.DataTables

NooBIT.DataTables provides functionality to process ajax requests from https://datatables.net javascript framework v1.10.x


Project Health

Service Status
AppVeyor Build status

Packages

Package NuGet
NooBIT.DataTables NuGet
NooBIT.DataTables.AspNetCore.Mvc NuGet

Usage

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

About

.NET Library for https://datatables.net/ v1.10.x

License:MIT License


Languages

Language:C# 100.0%