Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file table_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418open!Core_kernelopen!Import(** [Sort_key] determines what values the rows are sorted on. *)moduletypeSort_key=sig(** [t] is the type of the keys used to sort rows. Each row maps to a key of type [t]
based on the contents of the row and the current column being sorted on. *)typet[@@derivingsexp,compare]end(** [Sort_dir] determines the different ways in which the rows can be sorted
(e.g. ascending and descending). *)moduletypeSort_dir=sigtypet[@@derivingsexp,compare](** [next] cycles through sort directions. This is used to determine how to
update the sort direction when a header is clicked on. *)valnext:toption->toption(** [indicator], [header_class] and [indicator_class] convert the sort direction and
precedence of a column from the sort criteria into a string symbol and css classes
for the header and the indicator respectively in order to display sort information
in the table.
[indicator] returns a symbol that is displayed in the header of the corresponding
column, [header_class] returns a css class that is assigned to the header element,
and [indicator_class] returns a css class assigned to the indicator itself.
The [precedence] is always a positive integer (i.e. it starts at 1, not 0).
A column that is not in the sort criteria is assigned an [indicator] and classes of
[None].
Examples of suitable indicators are:
- "▲" (ascending with priority 1)
- "▲(2)" (ascending with priority 2)
*)valindicator:t->precedence:int->stringoptionvalheader_class:t->precedence:int->stringoptionvalindicator_class:t->precedence:int->stringoptionend(** [Sort_spec] defines how rows are sorted in the table. *)moduletypeSort_spec=sigmoduleSort_key:Sort_keymoduleSort_dir:Sort_dir(** [compare_keys] and [compare_rows_if_equal_keys] are comparison functions used to
compare rows in a table in order to sort them.
[compare_keys] compares two rows based on a single column in the table's sort
criteria.
[compare_rows_if_equal_keys] compares two rows based on their row ids, and is only
called if the calls to [compare_key] for all columns in the table's sort criteria
return 0. The sort direction is determined by the first column in the sort criteria.
*)valcompare_keys:Sort_dir.t->Sort_key.t->Sort_key.t->intvalcompare_rows_if_equal_keys:cmp_row_id:('row_id->'row_id->int)->Sort_dir.t->'row_id->'row_id->intendincludeUtilmoduletypeId=sigtypet[@@derivingsexp]includeComparable.Swithtypet:=tvalto_string:t->stringendmoduletypeS=sigmoduleRow_id:Id(** This isn't just an int so that if an app adds columns the sort is maintained
properly by the app's own classification instead of index. But it can be an int.*)moduleColumn_id:IdmoduleSort_spec:Sort_specmoduleSort_key=Sort_spec.Sort_keymoduleSort_dir=Sort_spec.Sort_dir(** A ['a Sort_criteria.t] specifies a list of columns by which to sort the rows of a
table, in order of precedence from highest to lowest. Each column's sort criteria is
made up of a direction and a value of type ['a], which varies as the sort criteria
goes through several rounds of processing. *)moduleSort_criteria:sigmoduleBy_column:sigtype'at={column:'a;dir:Sort_dir.t}[@@derivingfields,compare,sexp]endtype'at='aBy_column.tlist[@@derivingcompare,sexp]endmoduleBase_sort_criteria:sigtypet=Column_id.tSort_criteria.By_column.tlist[@@derivingcompare,sexp]valnone:tendmoduleHtml_id:sig(** HTML element ids *)valtable:Table_id.t->stringvaltbody:Table_id.t->stringvalthead:Table_id.t->stringvalcolumn_group:Table_id.t->stringvalcolumn_header:Table_id.t->stringvalcolumn_header_cell:Table_id.t->Column_id.t->stringvalrow:Table_id.t->Row_id.t->stringvalcell:Table_id.t->Row_id.t->Column_id.t->stringendmoduleColumn:sigtype'atvalcreate:?group:string(** optionally render a row above the headers with their group names (similar to
catalog). columns with the same group must be adjacent to be grouped together *)->?sort_by:(Row_id.t->'a->Sort_key.t)(** used to extract a sortable value for this column from a row. *)->?header_style:Css_gen.t(** Added to the style attribuate of the th node *)->header:Vdom.Node.t(** rendered at the top of the column.
this node is wrapped in a <th> node with other attributes *)->unit->'atvalgroup:_t->stringoptionvalsort_by:'at->(Row_id.t->'a->Sort_key.t)optionvalheader:_t->Vdom.Node.tend(** This is the key used for sorting functionality. Apps don't need to touch this to use
this widget, it is only exposed in case apps need to do something involving sorting
in the same way as the table will. *)moduleKey:sigtypet[@@derivingsexp]valsort_criteria:t->Sort_key.toptionLazy.tSort_criteria.tvalsort_keys:t->Sort_key.toptionLazy.tlistvalsort_dirs:t->Sort_dir.tlistvalrow_id:t->Row_id.tincludeComparable.Swithtypet:=tvalcreate:Sort_key.toptionLazy.tSort_criteria.t->Row_id.t->t(** Sorts a map of rows in the same way as using the table's built in sort *)valsort:'aColumn.tSort_criteria.t->rows:'aRow_id.Map.tIncr.t->'aMap.tIncr.tendmoduleModel:sigtypet[@@derivingcompare,sexp_of]valcreate:scroll_margin:Margin.t(** How far scroll_to and focus moving should keep the row from the [scroll_region] edge *)->scroll_region:Scroll_region.Id.t(** Element to scroll in scroll_to and focus moves *)->float_header:Float_type.t(** Whether to float the table header fixed to the top or to a specified position on
scrolling *)->float_first_col:Float_type.t->height_guess:float(** Estimated height of a normal row *)->?id:Table_id.t(** Id of the table. This must be a fresh id - one that has not been passed to
[Model.create] before - or behavior is undefined. It maybe be useful to provide
your own id here if you need access to the id before you create its associated
[Model.t]. *)->?initial_sort:Base_sort_criteria.t(** The column and sort direction that the table should be (initially) sorted by.
Sorting can be changed later via clicking on column headers. If [initial_sort]
is not specified, then the table is sorted by [Row_id]. *)->?initial_focus_row:Row_id.t->?initial_focus_col:Column_id.t->unit->tvalid:t->Table_id.tvalfloat_header:t->Float_type.tvalfloat_first_col:t->Float_type.tvalfocus_row:t->Row_id.toptionvalfocus_col:t->Column_id.toptionvalsort_criteria:t->Base_sort_criteria.tvalsort_columns:t->Column_id.tlistvalsort_dirs:t->Sort_dir.tlistvalscroll_margin:t->Margin.tvalset_float_first_col:t->Float_type.t->tvalset_float_header:t->Float_type.t->tvalset_scroll_margin:t->Margin.t->tvalset_sort_criteria:t->Base_sort_criteria.t->t(** [cycle_sorting] computes and sets new sort criteria based on the current criteria.
If the given column id already exists in the sort criteria, the column's sort
direction is updated by calling [next_dir] on its current sort direction.
Otherwise, the sort direction is computed by calling [next_dir] on [None]. If the
new direction is [None], the column id is removed from the sort criteria.
If [keep_existing_cols] is passed in as an argument, all existing column ids are
kept in the sort criteria, and the given column id is added or promoted to the
front of the sort criteria list (i.e. given the highest precedence).
If [keep_existing_cols] is not passed in, all column ids apart from the given one
are removed from the sort criteria.
*)valcycle_sorting:?keep_existing_cols:unit->t->Column_id.t->next_dir:(Sort_dir.toption->Sort_dir.toption)->t(** Returns the bounding client rectangle of the table body. *)valget_tbody_rect:t->floatJs_misc.Rect.toptionendmoduleAction:sigtypet=|Sort_column_clickedofColumn_id.t(** Moves the current focus in a given direction. If there is no focus it focuses
the top or bottom row on moving down and up respectively. *)|Move_focus_rowofFocus_dir.t|Move_focus_colofFocus_dir.t|Set_focus_rowofRow_id.toption|Set_focus_colofColumn_id.toption|Page_focus_rowofFocus_dir.t[@@derivingsexp,compare,variants]end(** Used to expose some extra information about a component that's useful for
applications that need more control over scrolling, sorting and focus management. *)moduleExtra:sigtype'atvalsorted_rows:'at->'aKey.Map.tvalsort_criteria:'at->'aColumn.tSort_criteria.tvalscroll_region:_t->Scroll_region.toption(** [current_key d row_id] returns [row_id]'s [Key.t] associated with the current sort
criteria of [d]. Returns [None] if [row_id] does not exist in [d] *)valcurrent_key:_t->row_id:Row_id.t->Key.toptionvalvisible_rows:'at->Row_id.tlist(** Functions [scroll_*_into_scroll_region] and [scroll_*_to_position] will always
work if the row heights in the model are correct (either because the row height
estimate is correct for all rows, or because all rows have already been rendered
and measured). If the row heights in the model are off, it may take multiple
iterations of calling the scroll function and then remeasuring row heights in
[update_visibility] before the specified element is successfully scrolled to its
target. *)valscroll_row_into_scroll_region:Model.t->_t->Row_id.t->Scroll_result.tvalscroll_col_into_scroll_region:Model.t->_t->Column_id.t->Scroll_result.tvalscroll_focus_into_scroll_region:Model.t->_t->Scroll_result.tvalscroll_row_to_position:?keep_in_scroll_region:unit->Model.t->_t->Row_id.t->position:float->Scroll_result.tvalscroll_col_to_position:?keep_in_scroll_region:unit->Model.t->_t->Column_id.t->position:float->Scroll_result.tvalscroll_focus_to_position:?keep_in_scroll_region:unit->Model.t->_t->position:float*float->Scroll_result.t(** Functions [*_is_in_scroll_region] and [get_*_position] return [None] if the
specified element is not found (e.g. there is no focus, or there is no row/column
with the given id), or if the visibility measurements are not yet available.
By default, the model's scroll margin is used to compute the bounds of the scroll
region. However, if a [scroll_margin] argument is given, that will be use instead.
*)valfocus_is_in_scroll_region:?scroll_margin:Margin.t->Model.t->_t->booloptionvalget_focus_position:Model.t->_t->floatoption*floatoption(** Returns the bounding client rectangle of the currently focused cell, if any.
This only returns a value if both the focus row and focus column are set. *)valget_focus_rect:Model.t->_t->floatJs_misc.Rect.toption(** Finds the row id at a given vertical position on the page, or indicates that the
position is before/after all the rows in the table.
It only returns [None] if the model has no visibility info. *)valfind_row_by_position:Model.t->_t->float->[`Before|`AtofRow_id.t|`After]option(** Finds the column id at a given horizontal position on the page, or indicates that
the position is before/after all the columns in the table.
It only returns [None] if the model has no visibility info or if a call to
[Dom_html.getElementById_opt] on a header cell id returns [None]. *)valfind_col_by_position:Model.t->_t->float->[`Before|`AtofColumn_id.t|`After]option(** Returns the vertical position one page away from the current focus (above for [dir
= Prev] or below for [dir = Next]). This can be used to implementing a
[page_focus_row] function in multi-table pages. Note that the position returned is
relative to the top of the page, not the top of the table. *)valpage_focus_row_target_position:Model.t->_t->dir:Focus_dir.t->floatoptionendvalset_focus_row:Model.t->Row_id.toption->Model.tvalset_focus_col:Model.t->Column_id.toption->Model.t(** When constructing the row [Vdom.Node.t] (most likely using function [Vdom.Node.tr]),
it is important to pass in the argument [~key:id]. Otherwise scrolling may have
unexpected behavior. *)type'arow_renderer=row_id:Row_id.t->row:'aIncr.t->Row_node_spec.tIncr.ttype'rowt=(Action.t,Model.t,unit,'rowExtra.t)Component.with_extra(** Returns a [Component.with_extra] with [Extra.t] as the extra value. The extra value
is not needed for most applications using the Table.
The input render_row should render <tr> nodes, and attrs should be a list of Vdom
attributes for the table. *)valcreate:?override_header_on_click:(Column_id.t->Dom_html.mouseEventJs.t->Vdom.Event.t)->Model.tIncr.t->old_model:Model.toptionIncr.t(** old_model can be set to None if the previous model did not exist or was in an
error state. *)->inject:(Action.t->Vdom.Event.t)->rows:'rowRow_id.Map.tIncr.t->columns:(Column_id.t*'rowColumn.t)listIncr.t(** This is a list and not a map so the app can decide order *)->render_row:'rowrow_renderer->attrs:Vdom.Attr.tlist->'rowtIncr.t(** Used for scrolling to rows/columns upon focusing them *)valon_display:old_model:Model.t->Model.t->_Extra.t->unit(** Used to handle sort column clicking *)valapply_action:Model.t->_Extra.t->Action.t->Model.t(** Measures rows, table and viewport *)valupdate_visibility:Model.t->_Extra.t->Model.t(** Returns a full partially-rendered <table> node with header. [render_row] function
should render <tr> nodes. *)valview:?override_header_on_click:(Column_id.t->Dom_html.mouseEventJs.t->Vdom.Event.t)->Model.tIncr.t->'aExtra.tIncr.t->render_row:'arow_renderer->inject:(Action.t->Vdom.Event.t)->attrs:Vdom.Attr.tlist->Vdom.Node.tIncr.tendmoduletypeTable=sig(** The Table widget is used to create incremental partially-rendered tables. It
provides sorting, focus and (possibly floating) table header support.
Behind the scenes it uses [Partial_render_list] so it works with very large tables
(e.g 10,000 rows). *)moduletypeS=SmoduletypeId=IdmoduleFocus_dir=Focus_dirmoduleMargin=MarginmoduleScroll_region=Scroll_regionmoduleFloat_type=Float_typemoduleMake(Row_id:Id)(Column_id:Id)(Sort_spec:Sort_spec):SwithmoduleRow_id=Row_idandmoduleColumn_id=Column_idandmoduleSort_spec=Sort_specend