mithril-materialized
    Preparing search index...

    Function DataTable

    • A comprehensive data table component with sorting, filtering, pagination, and selection capabilities.

      Type Parameters

      • T = Record<string, any>

        The type of data objects displayed in each row

      Returns Component<DataTableAttrs<T>>

      A Mithril component that renders the data table

      The DataTable component provides a feature-rich interface for displaying and interacting with tabular data. It supports both controlled and uncontrolled modes for all interactive features.

      Key Features:

      • Sorting: Click column headers to sort data ascending/descending
      • Filtering: Global search across filterable columns
      • Pagination: Navigate through large datasets with customizable page sizes
      • Selection: Single or multiple row selection with callbacks
      • Custom rendering: Use cellRenderer for complex cell content
      • Responsive: Adapts to different screen sizes
      • Internationalization: Customize all UI text
      • Accessibility: Proper ARIA attributes and keyboard navigation
      interface User { id: number; name: string; email: string; }
      const users: User[] = [...];
      const columns: DataTableColumn<User>[] = [
      { key: 'name', title: 'Name', field: 'name', sortable: true, filterable: true },
      { key: 'email', title: 'Email', field: 'email', sortable: true, filterable: true }
      ];

      return m(DataTable<User>, { data: users, columns });
      return m(DataTable<User>, {
      data: users,
      columns,
      title: 'User Management',
      striped: true,
      hoverable: true,
      height: 400,

      // Pagination
      pagination: { page: 0, pageSize: 10, total: users.length },
      onPaginationChange: (pagination) => console.log('Page changed:', pagination),

      // Selection
      selection: {
      mode: 'multiple',
      selectedKeys: [],
      getRowKey: (user) => String(user.id),
      onSelectionChange: (keys, selectedUsers) => console.log('Selection:', selectedUsers)
      },

      // Search
      enableGlobalSearch: true,
      searchPlaceholder: 'Search users...',

      // Events
      onRowClick: (user, index, event) => console.log('Clicked:', user),
      onRowDoubleClick: (user) => editUser(user),

      // Styling
      getRowClassName: (user) => user.active ? '' : 'inactive-row'
      });