Skip to content

Commit d373bab

Browse files
committed
Add jump-to-row functionality to data grid: implement input handling, validation, event wiring, UI integration, and test coverage.
1 parent 77060c0 commit d373bab

6 files changed

Lines changed: 559 additions & 94 deletions

File tree

_data_source_test.v

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@ fn test_data_grid_source_rows_text_cursor_opaque_fallback() {
195195
assert text == 'Rows 220/50000'
196196
}
197197

198+
fn test_data_grid_source_row_position_text_offset() {
199+
cfg := DataGridCfg{
200+
id: 'source-row-position'
201+
columns: []
202+
rows: [
203+
GridRow{
204+
id: '101'
205+
},
206+
GridRow{
207+
id: '102'
208+
},
209+
]
210+
selection: GridSelection{
211+
active_row_id: '102'
212+
}
213+
}
214+
state := DataGridSourceState{
215+
offset_start: 100
216+
row_count: ?int(500)
217+
}
218+
assert data_grid_source_row_position_text(cfg, state, .offset) == 'Row 102 of 500'
219+
}
220+
221+
fn test_data_grid_source_jump_enabled_rules() {
222+
cfg := DataGridCfg{
223+
id: 'source-jump'
224+
columns: []
225+
rows: []
226+
on_selection_change: fn (_ GridSelection, mut _ Event, mut _ Window) {}
227+
}
228+
state := DataGridSourceState{
229+
row_count: ?int(1000)
230+
}
231+
assert data_grid_source_jump_enabled(cfg, state, .offset, 200)
232+
assert !data_grid_source_jump_enabled(cfg, state, .cursor, 200)
233+
state_no_total := DataGridSourceState{}
234+
assert !data_grid_source_jump_enabled(cfg, state_no_total, .offset, 200)
235+
}
236+
198237
fn data_source_rows(count int) []GridRow {
199238
mut rows := []GridRow{cap: count}
200239
for i in 0 .. count {

_view_data_grid_test.v

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,92 @@ fn test_data_grid_quick_filter_matches_text_with_total() {
280280
assert data_grid_quick_filter_matches_text(cfg) == 'Matches 2/50'
281281
}
282282

283+
fn test_data_grid_jump_digits_and_target_parsing() {
284+
assert data_grid_jump_digits('1a-2') == '12'
285+
if target := data_grid_parse_jump_target('3', 10) {
286+
assert target == 2
287+
} else {
288+
assert false
289+
}
290+
if target := data_grid_parse_jump_target('999', 10) {
291+
assert target == 9
292+
} else {
293+
assert false
294+
}
295+
if _ := data_grid_parse_jump_target('0', 10) {
296+
assert false
297+
}
298+
if _ := data_grid_parse_jump_target('', 10) {
299+
assert false
300+
}
301+
}
302+
303+
fn test_data_grid_row_position_text_uses_page_start_without_selection() {
304+
mut rows := []GridRow{cap: 100}
305+
for i in 0 .. 100 {
306+
rows << GridRow{
307+
id: '${i + 1}'
308+
}
309+
}
310+
cfg := DataGridCfg{
311+
id: 'row-pos-page-start'
312+
page_size: 20
313+
columns: []
314+
rows: rows
315+
}
316+
assert data_grid_row_position_text(cfg, 40, 60, 100) == 'Row 41 of 100'
317+
}
318+
319+
fn test_data_grid_row_position_text_uses_active_row() {
320+
cfg := DataGridCfg{
321+
id: 'row-pos-active'
322+
columns: []
323+
rows: [
324+
GridRow{
325+
id: '1'
326+
},
327+
GridRow{
328+
id: '2'
329+
},
330+
GridRow{
331+
id: '3'
332+
},
333+
]
334+
selection: GridSelection{
335+
active_row_id: '2'
336+
}
337+
}
338+
assert data_grid_row_position_text(cfg, 0, 3, 3) == 'Row 2 of 3'
339+
}
340+
341+
fn test_data_grid_pager_padding_uses_cell_gutter_when_filter_padding_is_zero() {
342+
cfg := DataGridCfg{
343+
id: 'pager-padding-fallback'
344+
columns: []
345+
rows: []
346+
padding_cell: padding(0, 7, 0, 5)
347+
padding_filter: padding_none
348+
}
349+
pad := data_grid_pager_padding(cfg)
350+
assert pad.left == 5
351+
assert pad.right == 7
352+
}
353+
354+
fn test_data_grid_pager_padding_preserves_larger_filter_padding() {
355+
cfg := DataGridCfg{
356+
id: 'pager-padding-filter'
357+
columns: []
358+
rows: []
359+
padding_cell: padding(0, 4, 0, 3)
360+
padding_filter: padding(2, 10, 1, 8)
361+
}
362+
pad := data_grid_pager_padding(cfg)
363+
assert pad.top == 2
364+
assert pad.bottom == 1
365+
assert pad.left == 8
366+
assert pad.right == 10
367+
}
368+
283369
fn test_data_grid_scroll_padding_visible() {
284370
cfg := DataGridCfg{
285371
id: 'padding-visible'

examples/data_grid_data_source_demo.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn main_view(mut window gui.Window) gui.View {
7979
window.data_grid(
8080
id: 'source-grid'
8181
max_height: 620
82+
show_quick_filter: true
8283
columns: app.columns
8384
data_source: app.source
8485
pagination_kind: if app.use_offset {

0 commit comments

Comments
 (0)