1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
use ag_grid_derive::{FieldSetter, ToJsValue};
use wasm_bindgen::prelude::*;
use crate::types::{
Filter, IHeaderValueGetterParams, LockPosition, MenuTab, OneOrMany, PinnedPosition,
PopupPosition, SortMethod,
};
#[wasm_bindgen]
extern "C" {
/// A handle for the AG Grid [`Column API`].
///
/// [`Column API`]: https://www.ag-grid.com/javascript-data-grid/column-api/
pub type ColumnApi;
}
/// A customisable struct for defining a column.
#[derive(FieldSetter, ToJsValue)]
#[js_value(skip_serializing_none)]
pub struct ColumnDef {
// Base
#[field_setter(skip)]
field: Option<String>,
/// The unique ID to give the column. This is optional. If missing, the ID
/// will default to the field. If both field and colId are missing, a
/// unique ID will be generated. This ID is used to identify the column in
/// the API for sorting, filtering etc.
col_id: Option<String>,
/// A comma separated string or if using the [`ColumnDef::type_array`]
/// method, a vector of strings containing ColumnType keys which can be
/// used as a template for a column. This helps to reduce duplication of
/// properties when you have a lot of common column properties.
type_: Option<OneOrMany<String>>,
// TODO: support callback function
/// A function or expression that gets the value to be displayed from your
/// data.
value_getter: Option<String>,
// TODO: support callback function
/// A function or an expression to format a value. Not used for CSV export
/// or copy to clipboard; only for UI cell rendering.
value_formatter: Option<String>,
/// Provide a reference data map to be used to map column values to their
/// respective value from the map.
//ref_data: Option<HashMap<String, String>>,
/// Set to `true` to display a disabled checkbox when row is not selectable
/// and checkboxes are enabled.
show_disabled_checkboxes: Option<bool>,
// TODO
// Display
/// Set to `true` for this column to be hidden.
hide: Option<bool>,
/// Same as [`ColumnDef::hide`], except only applied when creating a new
/// column. Not applied when updating column definitions.
initial_hide: Option<bool>,
/// Set to `true` to block making column visible/hidden via the UI (API will
/// still work).
lock_visible: Option<bool>,
/// Lock a column to position to `Left` or `Right` to always have this
/// column displayed in that position. `True` is treated as `Left`.
lock_position: Option<LockPosition>,
/// Set to `true` if you do not want this column to be movable via dragging.
suppress_movable: Option<bool>,
// Editing
/// Set to `true` if this column is editable.
editable: Option<bool>, // TODO: add support for a callback function
/// Set to `true` to have the cell editor appear in a popup.
cell_editor_popup: Option<bool>,
/// Set the position for the popup cell editor. Possible values are `Over`,
/// whereby the popup will be positioned over the cell, or `Under`, whereby
/// the popup will be positioned below the cell leaving the cell value
/// visible.
cell_editor_popup_position: Option<PopupPosition>,
/// Set to `true` to have cells under this column enter edit mode after
/// single click.
single_click_edit: Option<bool>,
// TODO
// Events
// TODO
// Filter
/// Set whether the column is filterable, or use one of the provided
/// filters.
filter: Option<Filter>,
/// Whether to display a floating filter for this column.
floating_filter: Option<bool>,
// TODO
// Header
/// The name to render in the column header. If not specified and field is
/// specified, the field name will be used as the header name.
header_name: Option<String>,
/// Get the value for display in the header.
header_value_getter: Option<Closure<dyn FnMut(IHeaderValueGetterParams) -> String>>,
/// Tooltip for the column header.
header_tooltip: Option<String>,
/// CSS class to use for the header cell. Can be a string or, if using the
/// `header_class_array` method, a vector of strings.
header_class: Option<OneOrMany<String>>,
/// Set to `true` to wrap long header names onto the next line.
wrap_header_text: Option<bool>,
/// Set to `true` to enable the header row to automatically adjust its
/// height to accommodate the size of the header cell.
auto_header_height: Option<bool>,
/// Select which menu tabs are present, and in what order they are shown.
menu_tabs: Option<Vec<MenuTab>>,
/// Set to `true` to disable showing the menu for this column header.
suppress_menu: Option<bool>,
/// If `true`, a 'select all' checkbox will be put into the header.
header_checkbox_selection: Option<bool>, // TODO: add support for a callback function
/// If `true`, the header checkbox selection will only select filtered
/// items.
header_checkbox_selection_filtered_only: Option<bool>,
// TODO
// Integrated Charts
// All options are enterprise-only
// Pinned
/// Pin a column to one side: right or left. A value of `True` is converted
/// to `Left`.
pinned: Option<PinnedPosition>,
/// Same as [`ColumnDef::pinned`], except only applied when creating a new
/// column. Not applied when updating column definitions.
initial_pinned: Option<PinnedPosition>,
/// Set to `true` to block the user pinning the column, the column can only
/// be pinned via definitions or API.
lock_pinned: Option<bool>,
// Pivoting
// All options are enterprise-only
// Rendering and Styling
/// Set to `true` to have the grid calculate the height of a row based on
/// contents of this column.
auto_height: Option<bool>,
/// Set to `true` to have the text wrap inside the cell - typically used
/// with [`ColumnDef::auto_height`].
wrap_text: Option<bool>,
/// Set to `true` to flash a cell when it's refreshed.
enable_cell_change_flash: Option<bool>,
/// Set to `true` to prevent this column from flashing on changes. Only
/// applicable if cell flashing is turned on for the grid.
suppress_cell_flash: Option<bool>,
// TODO
// Row Dragging
/// Set to `true` to allow row dragging.
row_drag: Option<bool>, // TODO: add support for callback function
/// Set to `true` to allow dragging for native drag and drop.
dnd_source: Option<bool>, // TODO: add support for callback function
// TODO
// Row Grouping
// All options and enterprise-only
// Sort
/// Set wether the column is sortable.
sortable: Option<bool>,
/// Set the default sorting method.
sort: Option<SortMethod>,
/// The same as [`ColumnDef::sort`], except only applied when creating a new
/// column. Not applied when updating column definitions.
initial_sort: Option<SortMethod>,
/// If sorting more than one column by default, specifies order in which the
/// sorting should be applied.
sort_index: Option<Option<u32>>,
/// Vector defining the order in which sorting occurs (if sorting is
/// enabled). Expects a vector of any permutation of the [`SortMethod`]
/// variants.
sorting_order: Option<Vec<SortMethod>>,
/// Set to `true` if you want the unsorted icon to be shown when no sort is
/// applied to this column.
#[js_value(rename = "unSortIcon")]
unsort_icon: Option<bool>,
// Spanning
//
// TODO: support callback function
/// Set the span of the column.
col_span: Option<u32>,
// TODO: support callback function
/// Set the span of the row.
row_span: Option<u32>,
// Tooltips
/// The field of the tooltip to apply to the cell.
tooltip_field: Option<String>, // TODO
// Width
/// Initial width in pixels for the cell.
width: Option<u32>,
/// The same as [`ColumnDef::width`], except only applied when creating a
/// new column. Not applied when updating column definitions.
initial_width: Option<u32>,
/// Minimum width in pixels for the cell.
min_width: Option<u32>,
/// Maxmum width in pixels for the cell.
max_width: Option<u32>,
/// Used instead of width when the goal is to fill the remaining empty space
/// of the grid.
flex: Option<u32>,
/// The same as [`ColumnDef::flex`], except only applied when creating a new
/// column. Not applied when updating column definitions.
initial_flex: Option<u32>,
/// Set to `true` to allow this column to be resized.
resizable: Option<bool>,
/// Set to `true` if you want this column's width to be fixed during 'size
/// to fit' operations.
suppress_size_to_fit: Option<bool>,
/// Set to `true` if you do not want this column to be auto-resizable by
/// double clicking it's edge.
suppress_auto_size: Option<bool>,
}
impl ColumnDef {
/// Create a new column definition, specifying the field of the row object
/// to get the cell's data from. Deep references into a row object is
/// supported via dot notation, i.e 'address.firstLine'.
pub fn new<S: AsRef<str>>(field: S) -> Self {
Self {
field: Some(field.as_ref().to_string()),
..Default::default()
}
}
}