Class DataTablesColumns

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

public class DataTablesColumns extends Object
Generates a DataTables columns array from the bean properties of a row type, so the browser-side column list doesn't have to be hand-duplicated.

Each generated column descriptor carries the four fields DataTables reads for a server-side-processing column:

  • data — the bean property name (also the JSON key DataTables reads from each row).
  • title — the human-readable header. Sourced from @Schema(title) on the property (field or getter) when present, otherwise a humanized form of the property name (e.g. "releaseDate" → "Release Date").
  • orderable / searchable — both default to true (DataTables' own defaults), emitted explicitly so the array is self-describing.

Columns are emitted in Juneau bean-property order (the same order the negotiated serializer uses for the row data), so a generated columns array lines up positionally with the data rows in a DataTablesResults envelope.

Example:

// Bean whose properties drive both the server response and the browser column list. public class Release { public String getName() {...} @Schema(title="Ship date") public Date getReleaseDate() {...} } // [{data:'name',title:'Name',orderable:true,searchable:true}, // {data:'releaseDate',title:'Ship date',orderable:true,searchable:true}] List<Map<String,Object>> columns = DataTablesColumns.of(Release.class);

The result is an ordinary List<Map<String,Object>>; serialize it with any Juneau serializer (or embed it in a page) to produce the JSON DataTables' columns option expects.

See Also:
Since:
10.0.0
  • Method Details

    • of

      public static List<Map<String,Object>> of(Class<?> beanClass)
      Generates the DataTables columns array for the specified bean type using the default marshalling context.
      Parameters:
      beanClass - The row bean type. Must not be null and must be a bean.
      Returns:
      A new mutable list of column descriptors, in bean-property order.
      Throws:
      IllegalArgumentException - If the class is not a bean (no readable bean properties could be resolved).
    • of

      public static List<Map<String,Object>> of(MarshallingContext ctx, Class<?> beanClass)
      Generates the DataTables columns array for the specified bean type using the specified marshalling context.
      Parameters:
      ctx - The marshalling context supplying the bean metadata (e.g. property naming/ordering). Must not be null.
      beanClass - The row bean type. Must not be null and must be a bean.
      Returns:
      A new mutable list of column descriptors, in bean-property order.
      Throws:
      IllegalArgumentException - If the class is not a bean (no readable bean properties could be resolved).