1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4import { HorizontalBox, VerticalBox, StandardTableView, GroupBox, StyleMetrics, LineEdit } from "std-widgets.slint";
5import { GallerySettings } from "../gallery_settings.slint";
6import { Page } from "page.slint";
7
8export global TableViewPageAdapter {
9 in property <[[StandardListViewItem]]> row_data: [
10 [ { text: "Item 1.1" }, { text: "Item 1.2" }, { text: "Item 1.3" }, { text: "Item 1.4" }, ],
11 [ { text: "Item 2.1" }, { text: "Item 2.2" }, { text: "Item 2.3" }, { text: "Item 2.4" }, ],
12 [ { text: "Item 3.1" }, { text: "Item 3.2" }, { text: "Item 3.3" }, { text: "Item 3.4" }, ],
13 [ { text: "Item 4.1" }, { text: "Item 4.2" }, { text: "Item 4.3" }, { text: "Item 4.4" }, ],
14 [ { text: "Item 5.1" }, { text: "Item 5.2" }, { text: "Item 5.3" }, { text: "Item 5.4" }, ],
15 [ { text: "Item 6.1" }, { text: "Item 6.2" }, { text: "Item 6.3" }, { text: "Item 6.4" }, ],
16 ];
17
18 pure callback filter_sort_model([[StandardListViewItem]], string, int, bool) -> [[StandardListViewItem]];
19}
20
21export component TableViewPage inherits Page {
22 property <int> sort-index: -1;
23 property <bool> sort-ascending;
24
25 title: @tr("TableView");
26 show-enable-switch: false;
27 description: @tr("StandardTableView can be used to display a list of text elements in columns and rows. It can be imported from \"std-widgets.slint\"");
28
29 HorizontalBox {
30 vertical-stretch: 1;
31
32 GroupBox {
33 title: @tr("StandardTableView");
34 vertical-stretch: 0;
35
36 VerticalLayout {
37 spacing: StyleMetrics.layout-spacing;
38
39 StandardTableView {
40 sort-ascending(index) => {
41 root.sort-index = index;
42 root.sort-ascending = true;
43 }
44
45 sort-descending(index) => {
46 root.sort-index = index;
47 root.sort-ascending = false;
48 }
49
50 columns: [
51 { title: @tr("Header 1") },
52 { title: @tr("Header 2") },
53 { title: @tr("Header 3") },
54 { title: @tr("Header 4") },
55 ];
56 rows: TableViewPageAdapter.filter_sort_model(TableViewPageAdapter.row_data, filter-edit.text, root.sort-index, root.sort-ascending);
57 }
58
59 VerticalLayout {
60 Text {
61 text: @tr("Filter by Header 1:");
62 }
63
64 filter-edit := LineEdit {
65 placeholder-text: @tr("Enter filter text");
66 }
67 }
68 }
69 }
70 }
71}
72