Class DataTablesTable

java.lang.Object
org.apache.juneau.console.datatables.DataTablesTable

public class DataTablesTable extends Object
Builds a DataTables-ready HTML Table DOM bean from a collection of rows — a server-rendered "plain table" that the browser upgrades in place with $('#id').DataTable().

The generated table carries:

  • a stable id attribute (the selector the browser initializer targets),
  • a data-juneau-datatable marker attribute (the hook the shipped juneau-datatables.js glue auto-initializes — see DataTablesMixin),
  • a <thead> of column titles (from DataTablesColumns), and
  • a <tbody> of one <tr> per row, with cells pulled positionally from the column data keys.

Because it returns a Juneau Table DOM bean (not a raw HTML string), the markup is produced by the normal HtmlSerializer with its usual escaping — there's no bespoke string concatenation to get wrong. This helper is intentionally scoped to the juneau-console-datatables module so the marshall core and HtmlDocSerializer stay decoupled from any DataTables-specific rendering.

Example:

// Server-render the rows; the browser calls $('#releases').DataTable() to upgrade it. Table t = DataTablesTable.of("releases", releases, Release.class);

See Also:
Since:
10.0.0
  • Field Details

    • MARKER_ATTR

      public static final String MARKER_ATTR
      Marker attribute the shipped juneau-datatables.js glue looks for to auto-initialize a table.
      See Also:
    • AJAX_ATTR

      public static final String AJAX_ATTR
      Marker attribute carrying a server endpoint URL that the shipped juneau-datatables.js glue auto-wires into opts.ajax via JuneauDataTables.ajax(url) (with opts.serverSide defaulted to true) when the parsed MARKER_ATTR options have no ajax key.
      See Also:
  • Method Details

    • of

      public static Table of(String id, Collection<?> rows, Class<?> rowType)
      Builds a DataTables-ready table, deriving the columns from the specified row bean type via DataTablesColumns.of(Class).
      Parameters:
      id - The table's DOM id (the $('#id') selector). Must not be null.
      rows - The rows to render (beans or maps). Must not be null; may be empty.
      rowType - The row bean type used to derive the columns. Must not be null and must be a bean.
      Returns:
      A new Table DOM bean.
    • of

      public static Table of(MarshallingContext ctx, String id, Collection<?> rows, Class<?> rowType)
      Builds a DataTables-ready table using the specified marshalling context, deriving the columns from the specified row bean type via DataTablesColumns.of(MarshallingContext, Class), additively honoring each bean property's @Html(render) the same way the ordinary HtmlSerializer/HtmlDocSerializer path already does.

      Using one context for both column derivation and cell reads keeps the data keys and the row values consistent when a resource applies custom bean settings.

      Behavior note (not purely additive): a bean already carrying @Html(render=...) for the existing HtmlDoc/serializer path now ALSO renders through that same render when passed through this overload — this overload no longer delegates to the raw-value of(MarshallingContext, String, Collection, List) columns-overload path the way it used to.

      @Html(render) honoring applies to bean rows only. A Map-based row (bean rowType for columns, Map rows for values — supported today via value()'s row instanceof Map branch) has no BeanPropertyMeta to resolve a render from, so it keeps rendering the raw value, exactly as before.

      Parameters:
      ctx - The marshalling context supplying bean metadata (property naming/ordering) and cell reads. Must not be null.
      id - The table's DOM id (the $('#id') selector). Must not be null.
      rows - The rows to render (beans or maps). Must not be null; may be empty.
      rowType - The row bean type used to derive the columns. Must not be null and must be a bean.
      Returns:
      A new Table DOM bean.
    • of

      public static Table of(String id, Collection<?> rows, List<Map<String,Object>> columns)
      Builds a DataTables-ready table from an explicit column list (e.g. one produced by DataTablesColumns and then adjusted).
      Parameters:
      id - The table's DOM id (the $('#id') selector). Must not be null.
      rows - The rows to render (beans or maps). Must not be null; may be empty.
      columns - The column descriptors (each carrying at least data and title). Must not be null.
      Returns:
      A new Table DOM bean.
    • of

      public static Table of(MarshallingContext ctx, String id, Collection<?> rows, List<Map<String,Object>> columns)
      Builds a DataTables-ready table from an explicit column list using the specified marshalling context for bean-property cell reads.
      Parameters:
      ctx - The marshalling context used to read bean-property cell values. Must not be null.
      id - The table's DOM id (the $('#id') selector). Must not be null.
      rows - The rows to render (beans or maps). Must not be null; may be empty.
      columns - The column descriptors (each carrying at least data and title). Must not be null.
      Returns:
      A new Table DOM bean.