Class DataTablesResults<T>

java.lang.Object
org.apache.juneau.console.datatables.DataTablesResults<T>
Type Parameters:
T - The row type.

public class DataTablesResults<T> extends Object
The DataTables server-side-processing response envelope.

Serializes (via the normal negotiated serializer) to the JSON shape DataTables expects from a server-side source:

{ draw: 1, recordsTotal: 57, recordsFiltered: 12, data: [ ... ] }

  • draw — the draw counter echoed back from the request (cast to a number by DataTables).
  • recordsTotal — total records before filtering.
  • recordsFiltered — records after filtering (before paging).
  • data — the page of rows.
  • error — optional error message (omitted from the response when null).
Example:

// A normal page of results. DataTablesResults<Person> results = DataTablesResults.<Person>create() .setDraw(request.getDraw()) .setRecordsTotal(page.total().orElse(0)) .setRecordsFiltered(page.matched().orElse(0)) .setData(page.rows()); // An explicit application-level error envelope (HTTP 200; DataTablesQuery itself no longer builds one). DataTablesResults<Person> errorResults = DataTablesResults.error(request.getDraw(), "Unknown column 'x'.");

Since:
10.0.0
  • Constructor Details

  • Method Details

    • create

      public static <T> DataTablesResults<T> create()
      Static creator.
      Type Parameters:
      T - The row type.
      Returns:
      A new empty DataTablesResults.
    • error

      public static <T> DataTablesResults<T> error(int draw, String message)
      Builds an error envelope: the draw counter echoed back, no rows, and no counts, with the caller's error message.

      For an application-level failure an endpoint wants to report with HTTP 200 so DataTables surfaces error through its errMode. Note that DataTablesQuery no longer uses this for a BeanQuerySyntaxException (unknown column, too many search clauses, ...): since 2026-10-05 that propagates and is mapped centrally to HTTP 400 with an X-BeanQuery-Error header.

      Example:

      return DataTablesResults.error(request.getDraw(), "Unknown column 'x'.");

      Type Parameters:
      T - The row type.
      Parameters:
      draw - The draw counter to echo back.
      message - The error message to show.
      Returns:
      A new DataTablesResults with only draw and error set.
    • getDraw

      public int getDraw()
      Returns the draw counter.
      Returns:
      The draw counter.
    • setDraw

      public DataTablesResults<T> setDraw(int value)
      Sets the draw counter.
      Parameters:
      value - The value.
      Returns:
      This object.
    • getRecordsTotal

      public long getRecordsTotal()
      Returns the total record count before filtering.
      Returns:
      The total record count.
    • setRecordsTotal

      public DataTablesResults<T> setRecordsTotal(long value)
      Sets the total record count before filtering.
      Parameters:
      value - The value.
      Returns:
      This object.
    • getRecordsFiltered

      public long getRecordsFiltered()
      Returns the record count after filtering (before paging).
      Returns:
      The filtered record count.
    • setRecordsFiltered

      public DataTablesResults<T> setRecordsFiltered(long value)
      Sets the record count after filtering (before paging).
      Parameters:
      value - The value.
      Returns:
      This object.
    • getData

      public List<T> getData()
      Returns the page of rows.
      Returns:
      The page of rows. Can be null.
    • setData

      public DataTablesResults<T> setData(List<T> value)
      Sets the page of rows.
      Parameters:
      value - The value.
      Returns:
      This object.
    • getError

      public String getError()
      Returns the optional error message.
      Returns:
      The error message, or null if none.
    • setError

      Sets the optional error message.
      Parameters:
      value - The value.
      Returns:
      This object.