package bogue

  1. Overview
  2. Docs

Tables with sortable columns and selectable rows.

This module helps you create multi-column tables. You just need to provide the contents of each row.

  • Click on the column title to sort the table with respect to this column.
  • Click on a row to select or unselect it.
  • After clicking on a row, hit CTRL-A to select all rows at once.
  • After clicking a row, click on another row with SHIFT pressed to select a range of rows.
  • One can limit the maximum number of selected rows.
  • Actions can be executed when a row is clicked on.

Tables internally use a Long_list and hence will nicely handle a very large number of rows. A vertical scrollbar will appear as soon as the whole table height does not fit in the layout. However, contrary to Long_lists, in a table all rows must have the same height.


A three-column table (plus two buttons) (Example #35)
Dependency graph
type column = {
  1. title : string;
  2. length : int;
    (*

    number of entries in the column.

    *)
  3. rows : int -> Layout.t;
    (*

    row i should return the Layout corresponding to the ieth entry of that column.

    *)
  4. compare : (int -> int -> int) option;
    (*

    if a compare function is provided, then the column will be dynamically sortable by the user. compare i1 i2 > 0 means that entry i1 is larger than entry i2.

    *)
  5. min_width : int option;
    (*

    pixel width of the column. If not specified, the max width of the first 50 entries will be used.

    *)
  6. align : Draw.align option;
}
type t
val create : h:int -> ?row_height:int -> ?name:string -> ?on_click:(t -> int -> unit) -> ?max_selected:int -> ?selection:Selection.t -> ?on_select:(Selection.t -> unit) -> column list -> t

Create a table by specifying its list of columns; in each column, the entries can be arbitrary layouts. If entries are simple text labels, it's easier to use the helper functions of_array or of_list. If row_height is not specified, the height of the first row is used instead. The width of the table is determined by the min_width column parameters.

Some rows can be initially selected by providing the selection argument.

The function on_select is executed each time the selection is modified. Its argument is the new selection. This function is executed before the new selection is recorded in the table variable (of type t).

Everytime a row is clicked, the on_click function is called with two arguments: the table itself and the index of the row. (The first row has index 0. )

  • see Example #35

    .

val of_array : h:int -> ?widths:int option list -> ?row_height:int -> ?name:string -> ?on_click:(t -> int -> unit) -> ?max_selected:int -> ?selection:Selection.t -> ?on_select:(Selection.t -> unit) -> ?align:Draw.align -> string list -> string array array -> t

Create a table from an array of rows, each row being a string array.

  • see Example #35bis

    .

val of_list : h:int -> ?widths:int option list -> ?row_height:int -> ?name:string -> ?max_selected:int -> ?selection:Selection.t -> ?on_select:(Selection.t -> unit) -> ?align:Draw.align -> string list list -> t

Create a table from a list of rows, each row being a string list.

  • see Example #35ter

    .

val get_layout : t -> Layout.t

Use this layout to display your table.

val get_selection : t -> Selection.t

Which rows were selected by the user.

val set_selection : t -> Selection.t -> unit
val sort_column : t -> ?reverse:bool -> int -> unit
val min_width : t -> int

Hint for minimum width of the table layout; it's up to the user to enforce this.

val min_height : t -> int

Same remark.

OCaml

Innovation. Community. Security.