module Table:sig
..end
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.
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.
type
column = {
|
title : |
|||
|
length : |
(* | number of entries in the column. | *) |
|
rows : |
(* |
| *) |
|
compare : |
(* | if a compare function is provided, then the column will be dynamically
sortable by the user. | *) |
|
min_width : |
(* | pixel width of the column. If not specified, the max width of the first 50 entries will be used. | *) |
|
align : |
}
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 Table.of_array
or Table.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.
)
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.
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.
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.