跳转至

Tableview

Bases: Frame

A class built on the ttk.Treeview widget for arranging data in rows and columns. The underlying Treeview object and its methods are exposed in the Tableview.view property.

A Tableview object contains various features such has striped rows, pagination, and autosized and autoaligned columns.

The pagination option is recommended when loading a lot of data as the table records are inserted on-demand. Table records are only created when requested to be in a page view. This allows the table to be loaded very quickly even with hundreds of thousands of records.

All table columns are sortable. Clicking a column header will toggle between sorting "ascending" and "descending".

Columns are configurable by passing a simple list of header names or by passing in a dictionary of column names with settings. You can use both as well, as in the example below, where a column header name is use for one column, and a dictionary of settings is used for another.

The object has a right-click menu on the header and the cells that allow you to configure various settings.

Examples:

Adding data with the constructor
```python
import ttkbootstrap as ttk
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *

app = ttk.Window()
colors = app.style.colors

coldata = [
    {"text": "LicenseNumber", "stretch": False},
    "CompanyName",
    {"text": "UserCount", "stretch": False},
]

rowdata = [
    ('A123', 'IzzyCo', 12),
    ('A136', 'Kimdee Inc.', 45),
    ('A158', 'Farmadding Co.', 36)
]

dt = Tableview(
    master=app,
    coldata=coldata,
    rowdata=rowdata,
    paginated=True,
    searchable=True,
    bootstyle=PRIMARY,
    stripecolor=(colors.light, None),
)
dt.pack(fill=BOTH, expand=YES, padx=10, pady=10)

app.mainloop()
```

Add data with methods
```python
dt.insert_row('end', ['Marzale LLC', 26])
```
Source code in src/ttkbootstrap/tableview.py
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
class Tableview(ttk.Frame):
    """A class built on the `ttk.Treeview` widget for arranging data in
    rows and columns. The underlying Treeview object and its methods are
    exposed in the `Tableview.view` property.

    A Tableview object contains various features such has striped rows,
    pagination, and autosized and autoaligned columns.

    The pagination option is recommended when loading a lot of data as
    the table records are inserted on-demand. Table records are only
    created when requested to be in a page view. This allows the table
    to be loaded very quickly even with hundreds of thousands of
    records.

    All table columns are sortable. Clicking a column header will toggle
    between sorting "ascending" and "descending".

    Columns are configurable by passing a simple list of header names or
    by passing in a dictionary of column names with settings. You can
    use both as well, as in the example below, where a column header
    name is use for one column, and a dictionary of settings is used
    for another.

    The object has a right-click menu on the header and the cells that
    allow you to configure various settings.

    ![](../../assets/widgets/tableview-1.png)
    ![](../../assets/widgets/tableview-2.png)

    Examples:

        Adding data with the constructor
        ```python
        import ttkbootstrap as ttk
        from ttkbootstrap.tableview import Tableview
        from ttkbootstrap.constants import *

        app = ttk.Window()
        colors = app.style.colors

        coldata = [
            {"text": "LicenseNumber", "stretch": False},
            "CompanyName",
            {"text": "UserCount", "stretch": False},
        ]

        rowdata = [
            ('A123', 'IzzyCo', 12),
            ('A136', 'Kimdee Inc.', 45),
            ('A158', 'Farmadding Co.', 36)
        ]

        dt = Tableview(
            master=app,
            coldata=coldata,
            rowdata=rowdata,
            paginated=True,
            searchable=True,
            bootstyle=PRIMARY,
            stripecolor=(colors.light, None),
        )
        dt.pack(fill=BOTH, expand=YES, padx=10, pady=10)

        app.mainloop()
        ```

        Add data with methods
        ```python
        dt.insert_row('end', ['Marzale LLC', 26])
        ```
    """

    def __init__(
            self,
            master=None,
            bootstyle=DEFAULT,
            coldata=[],
            rowdata=[],
            paginated=False,
            searchable=False,
            yscrollbar=False,
            autofit=False,
            autoalign=True,
            stripecolor=None,
            pagesize=10,
            height=10,
            delimiter=",",
    ):
        """
        Parameters:

            master (Widget):
                The parent widget.

            bootstyle (str):
                A style keyword used to set the focus color of the entry
                and the background color of the date button. Available
                options include -> primary, secondary, success, info,
                warning, danger, dark, light.

            coldata (List[str | Dict]):
                An iterable containing either the heading name or a
                dictionary of column settings. Configurable settings
                include >> text, image, command, anchor, width, minwidth,
                maxwidth, stretch. Also see `Tableview.insert_column`.

            rowdata (List):
                An iterable of row data. The lenth of each row of data
                must match the number of columns. Also see
                `Tableview.insert_row`.

            paginated (bool):
                Specifies that the data is to be paginated. A pagination
                frame will be created below the table with controls that
                enable the user to page forward and backwards in the
                data set.

            pagesize (int):
                When `paginated=True`, this specifies the number of rows
                to show per page.

            searchable (bool):
                If `True`, a searchbar will be created above the table.
                Press the <Return> key to initiate a search. Searching
                with an empty string will reset the search criteria, or
                pressing the reset button to the right of the search
                bar. Currently, the search method looks for any row
                that contains the search text. The filtered results
                are displayed in the table view.

            yscrollbar (bool):
                If `True`, a vertical scrollbar will be created to the right
                of the table.

            autofit (bool):
                If `True`, the table columns will be automatically sized
                when loaded based on the records in the current view.
                Also see `Tableview.autofit_columns`.

            autoalign (bool):
                If `True`, the column headers and data are automatically
                aligned. Numbers and number headers are right-aligned
                and all other data types are left-aligned. The auto
                align method evaluates the first record in each column
                to determine the data type for alignment. Also see
                `Tableview.autoalign_columns`.

            stripecolor (Tuple[str, str]):
                If provided, even numbered rows will be color using the
                (background, foreground) specified. You may specify one
                or the other by passing in **None**. For example,
                `stripecolor=('green', None)` will set the stripe
                background as green, but the foreground will remain as
                default. You may use standand color names, hexadecimal
                color codes, or bootstyle color keywords. For example,
                ('light', '#222') will set the background to the "light"
                themed ttkbootstrap color and the foreground to the
                specified hexadecimal color. Also see
                `Tableview.apply_table_stripes`.

            height (int):
                Specifies how many rows will appear in the table's viewport.
                If the number of records extends beyond the table height,
                the user may use the mousewheel or scrollbar to navigate
                the data.

            delimiter (str):
                The character to use as a delimiter when exporting data
                to CSV.
        """
        super().__init__(master)
        self._tablecols = []
        self._tablerows = []
        self._tablerows_filtered = []
        self._viewdata = []
        self._rowindex = tk.IntVar(value=0)
        self._pageindex = tk.IntVar(value=1)
        self._pagelimit = tk.IntVar(value=0)
        self._height = height
        self._pagesize = tk.IntVar(value=pagesize)
        self._paginated = paginated
        self._searchable = searchable
        self._yscrollbar = yscrollbar
        self._stripecolor = stripecolor
        self._autofit = autofit
        self._autoalign = autoalign
        self._filtered = False
        self._sorted = False
        self._searchcriteria = tk.StringVar()
        self._rightclickmenu_cell = None
        self._delimiter = delimiter
        self._iidmap = {}  # maps iid to row object
        self._cidmap = {}  # maps cid to col object

        self.view: ttk.Treeview = None
        self._build_tableview_widget(coldata, rowdata, bootstyle)

    @property
    def tablerows(self):
        """A list of all tablerow objects"""
        return self._tablerows

    @property
    def tablerows_filtered(self):
        """A list of filtered tablerow objects"""
        return self._tablerows_filtered

    @property
    def tablerows_visible(self):
        """A list of visible tablerow objects"""
        return self._viewdata

    @property
    def tablecolumns(self):
        """A list of table column objects"""
        return self._tablecols

    @property
    def tablecolumns_visible(self):
        """A list of visible table column objects"""
        cids = list(self.view.cget("displaycolumns"))
        if "#all" in cids:
            return self._tablecols
        columns = []
        for cid in cids:
            # the cidmap expects an integer
            columns.append(self.cidmap.get(int(cid)))
        return columns

    @property
    def is_filtered(self):
        """Indicates whether the table is currently filtered"""
        return self._filtered

    @property
    def searchcriteria(self):
        """The criteria used to filter the records when the search
        method is invoked"""
        return self._searchcriteria.get()

    @searchcriteria.setter
    def searchcriteria(self, value):
        self._searchcriteria.set(value)

    @property
    def pagesize(self):
        """The number of records visible on a single page"""
        return self._pagesize.get()

    @pagesize.setter
    def pagesize(self, value):
        self._pagesize.set(value)

    @property
    def iidmap(self) -> Dict[str, TableRow]:
        """A map of iid to tablerow object"""
        return self._iidmap

    @property
    def cidmap(self) -> Dict[str, TableColumn]:
        """A map of cid to tablecolumn object"""
        return self._cidmap

    def configure(self, cnf=None, **kwargs) -> Union[Any, None]:
        """Configure the internal `Treeview` widget. If cnf is provided,
        value of the option is return. Otherwise the widget is
        configured via kwargs.

        Parameters:

            cnf (Any):
                An option to query.

            **kwargs (Dict):
                Optional keyword arguments used to configure the internal
                Treeview widget.

        Returns:

            Union[Any, None]:
                The value of cnf or None.
        """
        try:
            if "pagesize" in kwargs:
                pagesize: int = kwargs.pop("pagesize")
                self._pagesize.set(value=pagesize)

            self.view.configure(cnf, **kwargs)
        except:
            super().configure(cnf, **kwargs)

    # DATA HANDLING

    def build_table_data(self, coldata, rowdata):
        """Insert the specified column and row data.

        The coldata can be either a string column name or a dictionary
        of column settings that are passed to the `insert_column`
        method. You may use a mixture of string and dictionary in
        the list of coldata.

        !!!warning "Existing table data will be erased.
            This method will completely rebuild the underlying table
            with the new column and row data. Any existing data will
            be lost.

        Parameters:

            coldata (List[Union[str, Dict]]):
                An iterable of column names and/or settings.

            rowdata (List):
                An iterable of row values.
        """
        # destroy the existing data if existing
        self.purge_table_data()

        # build the table columns
        for i, col in enumerate(coldata):
            if isinstance(col, str):
                # just a column name
                self.insert_column(i, col)
            else:
                # a dictionary of column settings
                self.insert_column(i, **col)

        # build the table rows
        for values in rowdata:
            self.insert_row(values=values)

        # load the table data
        self.load_table_data()

        # apply table formatting
        if self._autofit:
            self.autofit_columns()

        if self._autoalign:
            self.autoalign_columns()

        if self._stripecolor is not None:
            self.apply_table_stripes(self._stripecolor)

        self.goto_first_page()

    def insert_row(self, index=END, values=[]) -> TableRow:
        """Insert a row into the tableview at index.

        You must call `Tableview.load_table_data()` to update the
        current view. If the data is filtered, you will need to call
        `Tableview.load_table_data(clear_filters=True)`.

        Parameters:

            index (Union[int, str]):
                A numerical index that specifieds where to insert
                the record in the dataset. You may also use the string
                'end' to append the record to the end of the data set.
                If the index exceeds the record count, it will be
                appended to the end of the dataset.

            values (Iterable):
                An iterable of values to insert into the data set.
                The number of columns implied by the list of values
                must match the number of columns in the data set for
                the values to be visible.

        Returns:

            TableRow:
                A table row object.
        """
        rowcount = len(self._tablerows)

        # validate the index
        if len(values) == 0:
            return
        if index == END:
            index = -1
        elif index > rowcount - 1:
            index = -1

        record = TableRow(self, values)
        if rowcount == 0 or index == -1:
            self._tablerows.append(record)
        else:
            self._tablerows.insert(index, record)

        return record

    def insert_rows(self, index, rowdata):
        """Insert row after index for each row in *row. If index does
        not exist then the records are appended to the end of the table.
        You can also use the string 'end' to append records at the end
        of the table.

        Parameters:

            index (Union[int, str]):
                The location in the data set after where the records
                will be inserted. You may use a numerical index or
                the string 'end', which will append the records to the
                end of the data set.

            rowdata (List[Any, List]):
                A list of row values to be inserted into the table.

        Examples:

            ```python
            Tableview.insert_rows('end', ['one', 1], ['two', 2])
            ```
        """
        if len(rowdata) == 0:
            return
        for values in reversed(rowdata):
            self.insert_row(index, values)

    def delete_column(self, index=None, cid=None, visible=True):
        """Delete the specified column based on the column index or the
        unique cid.

        Unless otherwise specified, the index refers to the column index
        as displayed in the tableview.

        If cid is provided, the column associated with the cid is deleted
        regardless of whether it is in the visible data sets.

        Parameters:

            index (int):
                The numerical index of the column.

            cid (str):
                A unique column indentifier.

            visible (bool):
                Specifies that the index should refer to the visible
                columns. Otherwise, if False, the original column
                position is used.
        """
        if cid is not None:
            column: TableColumn = self.cidmap(int(cid))
            column.delete()

        elif index is not None and visible:
            self.tablecolumns_visible[int(index)].delete()

        elif index is None and not visible:
            self.tablecolumns[int(index)].delete()

    def delete_columns(self, indices=None, cids=None, visible=True):
        """Delete columns specified by indices or cids.

        Unless specified otherwise, the index refers to the position
        of the columns in the table from left to right starting with
        index 0.

        !!!Warning "Use this method with caution!
            This method may or may not suffer performance issues.
            Internally, this method calls the `delete_column` method
            on each column specified in the list. The `delete_column`
            method deletes the related column from each record in
            the table data. So, if there are a lot of records this
            could be problematic. It may be more beneficial to use
            the `build_table_data` if you plan on changing the
            structure of the table dramatically.

        Parameters:

            indices (List[int]):
                A list of column indices to delete from the table.

            cids (List[str]):
                A list of unique column identifiers to delete from the
                table.

            visible (bool):
                If True, the index refers to the visible position of the
                column in the stable, from left to right starting at
                index 0.
        """
        if cids is not None:
            for cid in cids:
                self.delete_column(cid=cid)
        elif indices is not None:
            for index in indices:
                self.delete_column(index=index, visible=visible)

    def delete_row(self, index=None, iid=None, visible=True):
        """Delete a record from the data set.

        Unless specified otherwise, the index refers to the record
        position within the visible data set from top to bottom
        starting with index 0.

        If iid is provided, the record associated with the cid is deleted
        regardless of whether it is in the visible data set.

        Parameters:

            index (int):
                The numerical index of the record within the data set.

            iid (str):
                A unique record identifier.

            visible (bool):
                Indicates that the record index is relative to the current
                records in view, otherwise, the original data set index is
                used if False.
        """
        # delete from iid
        if iid is not None:
            record: TableRow = self.iidmap.get(iid)
            record.delete()
        elif index is not None:
            # visible index
            if visible:
                record = self.tablerows_visible[index]
                record.delete()
            # original index
            else:
                for record in self.tablerows:
                    if record._sort == index:
                        record.delete()

    def delete_rows(self, indices=None, iids=None, visible=True):
        """Delete rows specified by indices or iids.

        If both indices and iids are None, then all records in the
        table will be deleted.
        """
        # remove records by iid
        if iids is not None:
            for iid in iids:
                self.delete_row(iid=iid)
        # remove records by index
        elif indices is not None:
            for index in indices:
                self.delete_row(index=index, visible=visible)
        # remove ALL records
        else:
            self._tablerows.clear()
            self._tablerows_filtered.clear()
            self._viewdata.clear()
            self._iidmap.clear()
            records = self.view.get_children()
            self.view.delete(*records)
        # route to new page if no records visible
        if len(self._viewdata) == 0:
            self.goto_page()

    def insert_column(
            self,
            index,
            text="",
            image="",
            command="",
            anchor=W,
            width=200,
            minwidth=20,
            stretch=False,
    ) -> TableColumn:
        """
        Parameters:

            index (Union[int, str]):
                A numerical index that specifieds where to insert
                the column. You may also use the string 'end' to
                insert the column in the right-most position. If the
                index exceeds the column count, it will be inserted
                at the right-most position.

            text (str):
                The header text.

            image (PhotoImage):
                An image that is displayed to the left of the header text.

            command (Callable):
                A function called whenever the header button is clicked.

            anchor (str):
                The position of the header text within the header. One
                of "e", "w", "center".

            width (int):
                Specifies the width of the column in pixels.

            minwidth (int):
                Specifies the minimum width of the column in pixels.

            stretch (bool):
                Specifies whether or not the column width should be
                adjusted whenever the widget is resized or the user
                drags the column separator.

        Returns:

            TableColumn:
                A table column object.
        """
        self.reset_table()
        colcount = len(self.tablecolumns)
        cid = colcount
        if index == END:
            index = -1
        elif index > colcount - 1:
            index = -1

        # actual columns
        cols = self.view.cget("columns")
        if len(cols) > 0:
            cols = [int(x) for x in cols]
            cols.append(cid)
        else:
            cols = [cid]

        # visible columns
        dcols = self.view.cget("displaycolumns")
        if "#all" in dcols:
            dcols = cols
        elif len(dcols) > 0:
            dcols = [int(x) for x in dcols]
            if index == -1:
                dcols.append(cid)
            else:
                dcols.insert(index, cid)
        else:
            dcols = [cid]

        self.view.configure(columns=cols, displaycolumns=dcols)

        # configure new column
        column = TableColumn(
            tableview=self,
            cid=cid,
            text=text,
            image=image,
            command=command,
            anchor=anchor,
            width=width,
            minwidth=minwidth,
            stretch=stretch,
        )
        self._tablecols.append(column)
        # must be called to show the header after initially creating it
        # ad hoc, not sure why this should be the case;
        self._column_sort_header_reset()

        # update settings after they are erased when a column is
        #   inserted
        for column in self._tablecols:
            column.restore_settings()

        return column

    def purge_table_data(self):
        """Erase all table and column data.

        This method will completely destroy the table data structure.
        The table will need to be completely rebuilt after using this
        method.
        """
        self.delete_rows()
        self.cidmap.clear()
        self.tablecolumns.clear()
        self.view.configure(columns=[], displaycolumns=[])

    def unload_table_data(self):
        """Unload all data from the table"""
        for row in self.tablerows_visible:
            row.hide()
        self.tablerows_visible.clear()

    def load_table_data(self, clear_filters=False):
        """Load records into the tableview.

        Parameters:

            clear_filters (bool):
                Specifies that the table filters should be cleared
                before loading the data into the view.
        """
        if len(self.tablerows) == 0:
            return

        if clear_filters:
            self.reset_table()

        self.unload_table_data()

        if self._paginated:
            page_start = self._rowindex.get()
            page_end = self._rowindex.get() + self._pagesize.get()
        else:
            page_start = 0
            page_end = len(self._tablerows)

        if self._filtered:
            rowdata = self._tablerows_filtered[page_start:page_end]
            rowcount = len(self._tablerows_filtered)
        else:
            rowdata = self._tablerows[page_start:page_end]
            rowcount = len(self._tablerows)

        self._pagelimit.set(ceil(rowcount / self._pagesize.get()))

        pageindex = ceil(page_end / self._pagesize.get())
        pagelimit = self._pagelimit.get()
        self._pageindex.set(min([pagelimit, pageindex]))

        for i, row in enumerate(rowdata):
            if self._stripecolor is not None and i % 2 == 0:
                row.show(True)
            else:
                row.show(False)
            self._viewdata.append(row)

    def fill_empty_columns(self, fillvalue=""):
        """Fill empty columns with the fillvalue.

        This method can be used to fill in missing values when a column
        column is inserted after data has already been inserted into
        the tableview.

        Parameters:

            fillvalue (Any):
                A value to insert into an empty column
        """
        rowcount = len(self._tablerows)
        if rowcount == 0:
            return
        colcount = len(self._tablecols)
        for row in self._tablerows:
            var = colcount - len(row._values)
            if var <= 0:
                return
            else:
                for _ in range(var):
                    row._values.append(fillvalue)
                row.configure(values=row._values)

    # CONFIGURATION

    def get_columns(self) -> List[TableColumn]:
        """Returns a list of all column objects. Same as using the
        `Tableview.tablecolumns` property."""
        return self._tablecols

    def get_column(
            self, index=None, visible=False, cid=None
    ) -> TableColumn:
        """Returns the `TableColumn` object from an index or a cid.

        If index is specified, the column index refers to the index
        within the original, unless the visible flag is set, in which
        case the index is relative to the visible columns in view.

        If cid is specified, the column associated with the cid is
        return regardless of whether it is visible.

        Parameters:

            index (int):
                The numerical index of the column.

            visible (bool):
                Use the index of the visible columns as they appear
                in the table.

        Returns:

            Union[TableColumn, None]:
                The table column object if found, otherwise None.
        """
        if cid is not None:
            return self._cidmap.get(cid)

        if not visible:
            # original column index
            try:
                return self._tablecols[index]
            except IndexError:
                return None
        else:
            # visible column index
            cols = self.view.cget("columns")
            if len(cols) > 0:
                cols = [int(x) for x in cols]
            else:
                cols = []

            dcols = self.view.cget("displaycolumns")
            if "#all" in dcols:
                dcols = cols
            else:
                try:
                    x = int(dcols[index])
                    for c in self._tablecols:
                        if c.cid == x:
                            return c
                except ValueError:
                    return None

    def get_rows(self, visible=False, filtered=False, selected=False) -> List[TableRow]:
        """Return a list of TableRow objects.

        Return a subset of rows based on optional flags. Only ONE flag can be used
        at a time. If more than one flag is set to `True`, then the first flag will
        be used to return the data.

        Parameters:

            visible (bool):
                If true, only records in the current view will be returned.

            filtered (bool):
                If True, only rows in the filtered dataset will be returned.

            selected (bool):
                If True, only rows that are currently selected will be returned.

        Returns:

            List[TableRow]:
                A list of TableRow objects.
        """
        if visible:
            return self._viewdata
        elif filtered:
            return self._tablerows_filtered
        elif selected:
            return [row for row in self._viewdata if row.iid in self.view.selection()]
        else:
            return self._tablerows

    def get_row(self, index=None, visible=False, filtered=False, iid=None) -> TableRow:
        """Returns the `TableRow` object from an index or the iid.

        If an index is specified, the row index refers to the index
        within the original dataset. When choosing a subset of data,
        the visible data takes priority over filtered if both flags
        are set.

        If an iid is specified, the object attached to that iid is
        returned regardless of whether or not it is visible or
        filtered.

        Parameters:

            index (int):
                The numerical index of the column.

            iid (str):
                A unique column identifier.

            visible (bool):
                Use the index of the visible rows as they appear
                in the current table view.

            filtered (bool):
                Use the index of the rows within the filtered data
                set.

        Returns:

            Union[TableRow, None]:
                The table column object if found, otherwise None
        """
        if iid is not None:
            return self.iidmap.get(iid)

        if visible:
            try:
                return self.tablerows_visible[index]
            except IndexError:
                return None
        elif filtered:
            try:
                return self.tablerows_filtered[index]
            except IndexError:
                return None
        else:
            try:
                return self.tablerows[index]
            except IndexError:
                return None

    # PAGE NAVIGATION

    def _select_first_visible_item(self):
        try:
            iid = self.tablerows_visible[0].iid
            self.view.selection_set(iid)
            # must force focus, sometimes just focus on iid doesn't work
            self.view.focus_force()
            # this sets the focus on the specific row item
            self.view.focus(iid)
            # make sure the row is visible
            self.view.see(iid)
        except:
            pass

    def goto_first_page(self):
        """Update table with first page of data"""
        self._rowindex.set(0)
        self.load_table_data()
        self._select_first_visible_item()

    def goto_last_page(self):
        """Update table with the last page of data"""
        pagelimit = self._pagelimit.get() - 1
        self._rowindex.set(self.pagesize * pagelimit)
        self.load_table_data()
        self._select_first_visible_item()

    def goto_next_page(self):
        """Update table with next page of data"""
        if self._pageindex.get() >= self._pagelimit.get():
            return
        rowindex = self._rowindex.get()
        self._rowindex.set(rowindex + self.pagesize)
        self.load_table_data()
        self._select_first_visible_item()

    def goto_prev_page(self):
        """Update table with prev page of data"""
        if self._pageindex.get() <= 1:
            return
        rowindex = self._rowindex.get()
        self._rowindex.set(rowindex - self.pagesize)
        self.load_table_data()
        self._select_first_visible_item()

    def goto_page(self, *_):
        """Go to a specific page indicated by the page entry widget."""
        pagelimit = self._pagelimit.get()
        pageindex = self._pageindex.get()
        if pageindex > pagelimit:
            pageindex = pagelimit
            self._pageindex.set(pageindex)
        elif pageindex <= 0:
            pageindex = 1
            self._pageindex.set(pageindex)
        rowindex = (pageindex * self.pagesize) - self.pagesize
        self._rowindex.set(rowindex)
        self.load_table_data()
        self._select_first_visible_item()

    # COLUMN SORTING

    def sort_column_data(self, event=None, cid=None, sort=None):
        """Sort the table rows by the specified column. This method
        may be trigged by an event or manually.

        Parameters:

            event (Event):
                A window event.

            cid (int):
                A unique column identifier; typically the numerical
                index of the column relative to the original data set.

            sort (int):
                Determines the sort direction. 0 = ASCENDING. 1 = DESCENDING.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column
            index = column.tableindex
        elif cid is not None:
            column: TableColumn = self.cidmap.get(int(cid))
            index = column.tableindex
        else:
            return

        # update table data
        if self.is_filtered:
            tablerows = self.tablerows_filtered
        else:
            tablerows = self.tablerows

        if sort is not None:
            columnsort = sort
        else:
            columnsort = self.tablecolumns[index].columnsort

        if columnsort == ASCENDING:
            self._tablecols[index].columnsort = DESCENDING
        else:
            self._tablecols[index].columnsort = ASCENDING

        try:
            sortedrows = sorted(
                tablerows, reverse=columnsort, key=lambda x: x.values[index]
            )
        except:
            # when data is missing, or sometimes with numbers
            # this is still not right, but it works most of the time
            # fix sometime down the road when I have time
            self.fill_empty_columns()
            sortedrows = sorted(
                tablerows, reverse=columnsort, key=lambda x: int(x.values[index])
            )
        if self.is_filtered:
            self._tablerows_filtered = sortedrows
        else:
            self._tablerows = sortedrows

        # update headers
        self._column_sort_header_reset()
        self._column_sort_header_update(column.cid)

        self.unload_table_data()
        self.load_table_data()
        self._select_first_visible_item()

    # DATA SEARCH & FILTERING

    def reset_row_filters(self):
        """Remove all row level filters; unhide all rows."""
        self._filtered = False
        self.searchcriteria = ""
        self.unload_table_data()
        self.load_table_data()

    def reset_column_filters(self):
        """Remove all column level filters; unhide all columns."""
        cols = [col.cid for col in self.tablecolumns]
        self.view.configure(displaycolumns=cols)

    def reset_row_sort(self):
        """Display all table rows by original insert index"""
        ...

    def reset_column_sort(self):
        """Display all columns by original insert index"""
        cols = sorted([col.cid for col in self.tablecolumns_visible], key=int)
        self.view.configure(displaycolumns=cols)

    def reset_table(self):
        """Remove all table data filters and column sorts"""
        self._filtered = False
        self.searchcriteria = ""
        try:
            sortedrows = sorted(self.tablerows, key=lambda x: x._sort)
        except IndexError:
            self.fill_empty_columns()
            sortedrows = sorted(self.tablerows, key=lambda x: x._sort)
        self._tablerows = sortedrows
        self.unload_table_data()

        # reset the columns
        self.reset_column_filters()
        self.reset_column_sort()

        self._column_sort_header_reset()
        self.goto_first_page()  # needed?

    def filter_column_to_value(self, event=None, cid=None, value=None):
        """Hide all records except for records where the current
        column exactly matches the provided value. This method may
        be triggered by a window event or by specifying the column id.

        Parameters:

            event (Event):
                A window click event.

            cid (int):
                A unique column identifier; typically the numerical
                index of the column within the original dataset.

            value (Any):
                The criteria used to filter the column.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            index = eo.column.tableindex
            value = value or eo.row.values[index]
        elif cid is not None:
            column: TableColumn = self.cidmap.get(cid)
            index = column.tableindex
        else:
            return

        self._filtered = True
        self.tablerows_filtered.clear()
        self.unload_table_data()

        for row in self.tablerows:
            if row.values[index] == value:
                self.tablerows_filtered.append(row)

        self._rowindex.set(0)
        self.load_table_data()

    def filter_to_selected_rows(self):
        """Hide all records except for the selected rows"""
        criteria = self.view.selection()
        if len(criteria) == 0:
            return  # nothing is selected

        if self.is_filtered:
            for row in self.tablerows_visible:
                if row.iid not in criteria:
                    row.hide()
                    self.tablerows_filtered.remove(row)
        else:
            self._filtered = True
            self.tablerows_filtered.clear()
            for row in self.tablerows_visible:
                if row.iid in criteria:
                    self.tablerows_filtered.append(row)
        self._rowindex.set(0)
        self.load_table_data()

    def hide_selected_rows(self):
        """Hide the currently selected rows"""
        selected = self.view.selection()
        view_cnt = len(self._viewdata)
        hide_cnt = len(selected)
        self.view.detach(*selected)

        tablerows = []
        for row in self.tablerows_visible:
            if row.iid in selected:
                tablerows.append(row)

        if not self.is_filtered:
            self._filtered = True
            self._tablerows_filtered = self.tablerows.copy()

        for row in tablerows:
            if self.is_filtered:
                self.tablerows_filtered.remove(row)

        if hide_cnt == view_cnt:
            # assuming that if the count of the records on the page are
            #   selected for hiding, then need to go to the next page
            # The call to `load_table_data` is duplicative, but currently
            #   this is the only way to get this to work until I've
            #   refactored this bit.
            self.load_table_data()
            self.goto_page()
        else:
            self.load_table_data()

    def hide_selected_column(self, event=None, cid=None):
        """Detach the selected column from the tableview. This method
        may be triggered by a window event or by specifying the column
        id.

        Parameters:

            event (Event):
                A window click event

            cid (int):
                A unique column identifier; typically the numerical
                index of the column within the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column.hide()
        elif cid is not None:
            column: TableColumn = self.cidmap.get(cid)
            column.hide()

    def unhide_selected_column(self, event=None, cid=None):
        """Attach the selected column to the tableview. This method
        may be triggered by a window event or by specifying the column
        id. The column is reinserted at the index in the original data
        set.

        Parameters:

            event (Event):
                An application click event

            cid (int):
                A unique column identifier; typically the numerical
                index of the column within the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            eo.column.show()
        elif cid is not None:
            column = self.cidmap.get(cid)
            column.show()

    # DATA EXPORT

    def export_all_records(self):
        """Export all records to a csv file"""
        headers = [col.headertext for col in self.tablecolumns]
        records = [row.values for row in self.tablerows]
        self.save_data_to_csv(headers, records, self._delimiter)

    def export_current_page(self):
        """Export records on current page to csv file"""
        headers = [col.headertext for col in self.tablecolumns]
        records = [row.values for row in self.tablerows_visible]
        self.save_data_to_csv(headers, records, self._delimiter)

    def export_current_selection(self):
        """Export rows currently selected to csv file"""
        headers = [col.headertext for col in self.tablecolumns]
        selected = self.view.selection()
        records = []
        for iid in selected:
            record: TableRow = self.iidmap.get(iid)
            records.append(record.values)
        self.save_data_to_csv(headers, records, self._delimiter)

    def export_records_in_filter(self):
        """Export rows currently filtered to csv file"""
        headers = [col.headertext for col in self.tablecolumns]
        if not self.is_filtered:
            return
        records = [row.values for row in self.tablerows_filtered]
        self.save_data_to_csv(headers, records, self._delimiter)

    def save_data_to_csv(self, headers, records, delimiter=","):
        """Save data records to a csv file.

        Parameters:

            headers (List[str]):
                A list of header labels.

            records (List[Tuple[...]]):
                A list of table records.

            delimiter (str):
                The character to use for delimiting the values.
        """
        from tkinter.filedialog import asksaveasfilename
        import csv

        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        initialfile = f"tabledata_{timestamp}.csv"
        filetypes = [
            ("CSV UTF-8 (Comma delimited)", "*.csv"),
            ("All file types", "*.*"),
        ]
        filename = asksaveasfilename(
            confirmoverwrite=True,
            filetypes=filetypes,
            defaultextension="csv",
            initialfile=initialfile,
        )
        if filename:
            with open(filename, "w", encoding="utf-8", newline="") as f:
                writer = csv.writer(f, delimiter=delimiter)
                writer.writerow(headers)
                writer.writerows(records)

    # ROW MOVEMENT

    def move_selected_rows_to_top(self):
        """Move the selected rows to the top of the data set"""
        selected = self.view.selection()
        if len(selected) == 0:
            return

        if self.is_filtered:
            tablerows = self.tablerows_filtered.copy()
        else:
            tablerows = self.tablerows.copy()

        for i, iid in enumerate(selected):
            row = self.iidmap.get(iid)
            tablerows.remove(row)
            tablerows.insert(i, row)

        if self.is_filtered:
            self._tablerows_filtered = tablerows
        else:
            self._tablerows = tablerows

        # refresh the table data
        self.unload_table_data()
        self.load_table_data()

    def move_selected_rows_to_bottom(self):
        """Move the selected rows to the bottom of the dataset"""
        selected = self.view.selection()
        if len(selected) == 0:
            return

        if self.is_filtered:
            tablerows = self.tablerows_filtered.copy()
        else:
            tablerows = self.tablerows.copy()

        for iid in selected:
            row = self.iidmap.get(iid)
            tablerows.remove(row)
            tablerows.append(row)

        if self.is_filtered:
            self._tablerows_filtered = tablerows
        else:
            self._tablerows = tablerows

        # refresh the table data
        self.unload_table_data()
        self.load_table_data()

    def move_selected_row_up(self):
        """Move the selected rows up one position in the dataset"""
        selected = self.view.selection()
        if len(selected) == 0:
            return

        if self.is_filtered:
            tablerows = self._tablerows_filtered.copy()
        else:
            tablerows = self.tablerows.copy()

        for iid in selected:
            row = self.iidmap.get(iid)
            index = tablerows.index(row) - 1
            tablerows.remove(row)
            tablerows.insert(index, row)

        if self.is_filtered:
            self._tablerows_filtered = tablerows
        else:
            self._tablerows = tablerows

        # refresh the table data
        self.unload_table_data()
        self.load_table_data()

    def move_row_down(self):
        """Move the selected rows down one position in the dataset"""
        selected = self.view.selection()
        if len(selected) == 0:
            return

        if self._filtered:
            tablerows = self._tablerows_filtered
        else:
            tablerows = self._tablerows

        for iid in selected:
            row = self.iidmap.get(iid)
            index = tablerows.index(row) + 1
            tablerows.remove(row)
            tablerows.insert(index, row)

        if self._filtered:
            self._tablerows_filtered = tablerows
        else:
            self._tablerows = tablerows

        # refresh the table data
        self.unload_table_data()
        self.load_table_data()

    # COLUMN MOVEMENT

    def move_column_left(self, event=None, cid=None):
        """Move column one position to the left. This can be triggered
        by either an event, or by passing in the `cid`, which is the
        index of the column relative to the original data set.

        Parameters:

            event (Event):
                An application click event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column
        elif cid is not None:
            column = self.cidmap.get(cid)
        else:
            return

        displaycols = [x.cid for x in self.tablecolumns_visible]
        old_index = column.displayindex
        if old_index == 0:
            return

        new_index = column.displayindex - 1
        displaycols.insert(new_index, displaycols.pop(old_index))
        self.view.configure(displaycolumns=displaycols)

    def move_column_right(self, event=None, cid=None):
        """Move column one position to the right. This can be triggered
        by either an event, or by passing in the `cid`, which is the
        index of the column relative to the original data set.

        Parameters:

            event (Event):
                An application click event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column
        elif cid is not None:
            column = self.cidmap.get(cid)
        else:
            return

        displaycols = [x.cid for x in self.tablecolumns_visible]
        old_index = column.displayindex
        if old_index == len(displaycols) - 1:
            return

        new_index = old_index + 1
        displaycols.insert(new_index, displaycols.pop(old_index))
        self.view.configure(displaycolumns=displaycols)

    def move_column_to_first(self, event=None, cid=None):
        """Move column to leftmost position. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the column relative to the original data set.

        Parameters:

            event (Event):
                An application click event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column
        elif cid is not None:
            column = self.cidmap.get(cid)
        else:
            return

        displaycols = [x.cid for x in self.tablecolumns_visible]
        old_index = column.displayindex
        if old_index == 0:
            return

        displaycols.insert(0, displaycols.pop(old_index))
        self.view.configure(displaycolumns=displaycols)

    def move_column_to_last(self, event=None, cid=None):
        """Move column to the rightmost position. This can be triggered
        by either an event, or by passing in the `cid`, which is the
        index of the column relative to the original data set.

        Parameters:

            event (Event):
                An application click event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            column = eo.column
        elif cid is not None:
            column = self.cidmap.get(cid)
        else:
            return

        displaycols = [x.cid for x in self.tablecolumns_visible]
        old_index = column.displayindex
        if old_index == len(displaycols) - 1:
            return

        new_index = len(displaycols) - 1
        displaycols.insert(new_index, displaycols.pop(old_index))
        self.view.configure(displaycolumns=displaycols)

    # OTHER FORMATTING

    def apply_table_stripes(self, stripecolor):
        """Add stripes to even-numbered table rows as indicated by the
        `stripecolor` of (background, foreground). Either element may be
        specified as `None`, but both elements must be present.

        Parameters:

            stripecolor (Tuple[str, str]):
                A tuple of colors to apply to the table stripe. The
                tuple represents (background, foreground).
        """
        style: ttk.Style = ttk.Style.get_instance()
        colors = style.colors
        if len(stripecolor) == 2:
            self._stripecolor = stripecolor
            bg, fg = stripecolor
            kw = {}
            if bg is None:
                kw["background"] = colors.active
            else:
                kw["background"] = bg
            if fg is None:
                kw["foreground"] = colors.inputfg
            else:
                kw["foreground"] = fg
            self.view.tag_configure("striped", **kw)

    def autofit_columns(self):
        """Autofit all columns in the current view"""
        f = font.nametofont("TkDefaultFont")
        pad = utility.scale_size(self, 20)
        col_widths = []

        # measure header sizes
        for col in self.tablecolumns:
            width = f.measure(f"{col._headertext} {DOWNARROW}") + pad
            col_widths.append(width)

        for row in self.tablerows_visible:
            values = row.values
            for i, value in enumerate(values):
                old_width = col_widths[i]
                new_width = f.measure(str(value)) + pad
                width = max(old_width, new_width)
                col_widths[i] = width

        for i, width in enumerate(col_widths):
            self.view.column(i, width=width)

    # COLUMN AND HEADER ALIGNMENT

    def autoalign_columns(self):
        """Align the columns and headers based on the data type of the
        values. Text is left-aligned; numbers are right-aligned. This
        method will have no effect if there is no data in the tables."""
        if len(self._tablerows) == 0:
            return

        values = self._tablerows[0]._values
        for i, value in enumerate(values):
            if str(value).isnumeric():
                self.view.column(i, anchor=E)
                self.view.heading(i, anchor=E)
            else:
                self.view.column(i, anchor=W)
                self.view.heading(i, anchor=W)

    def align_column_left(self, event=None, cid=None):
        """Left align the column text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the column relative to the original data set.

        Parameters:

            event (Event):
                An application click event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.column(eo.column.cid, anchor=W)
        elif cid is not None:
            self.view.column(cid, anchor=W)

    def align_column_right(self, event=None, cid=None):
        """Right align the column text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the column relative to the original data set.

        Parameters:

            event (Event):
                An application event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.column(eo.column.cid, anchor=E)
        elif cid is not None:
            self.view.column(cid, anchor=E)

    def align_column_center(self, event=None, cid=None):
        """Center align the column text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the column relative to the original data set.

        Parameters:

            event (Event):
                An application event.

            cid (int):
                A unique column identifier; typically the index of the
                column relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.column(eo.column.cid, anchor=CENTER)
        elif cid is not None:
            self.view.column(cid, anchor=CENTER)

    def align_heading_left(self, event=None, cid=None):
        """Left align the heading text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the heading relative to the original data set.

        Parameters:

            event (Event):
                An application event.

            cid (int):
                A unique heading identifier; typically the index of the
                heading relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.heading(eo.column.cid, anchor=W)
        elif cid is not None:
            self.view.heading(cid, anchor=W)

    def align_heading_right(self, event=None, cid=None):
        """Right align the heading text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the heading relative to the original data set.

        Parameters:

            event (Event):
                An application event.

            cid (int):
                A unique heading identifier; typically the index of the
                heading relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.heading(eo.column.cid, anchor=E)
        elif cid is not None:
            self.view.heading(cid, anchor=E)

    def align_heading_center(self, event=None, cid=None):
        """Center align the heading text. This can be triggered by
        either an event, or by passing in the `cid`, which is the index
        of the heading relative to the original data set.

        Parameters:

            event (Event):
                An application event.

            cid (int):
                A unique heading identifier; typically the index of the
                heading relative to the original dataset.
        """
        if event is not None:
            eo = self._get_event_objects(event)
            self.view.heading(eo.column.cid, anchor=CENTER)
        elif cid is not None:
            self.view.heading(cid, anchor=CENTER)

    # PRIVATE METHODS

    def _get_event_objects(self, event):
        iid = self.view.identify_row(event.y)
        col = self.view.identify_column(event.x)
        cid = int(self.view.column(col, "id"))
        column: TableColumn = self.cidmap.get(cid)
        row: TableRow = self.iidmap.get(iid)
        data = TableEvent(column, row)
        return data

    def _search_table_data(self, _):
        """Search the table data for records that meet search criteria.
        Currently, this search locates any records that contain the
        specified text; it is also case insensitive.
        """
        criteria = self._searchcriteria.get()
        self._filtered = True
        self.tablerows_filtered.clear()
        self.unload_table_data()
        for row in self.tablerows:
            for col in row.values:
                if str(criteria).lower() in str(col).lower():
                    self.tablerows_filtered.append(row)
                    break
        self._rowindex.set(0)
        self.load_table_data()

    # PRIVATE METHODS - SORTING

    def _column_sort_header_reset(self):
        """Remove the sort character from the column headers"""
        for col in self.tablecolumns:
            self.view.heading(col.cid, text=col.headertext)

    def _column_sort_header_update(self, cid):
        """Add sort character to the sorted column"""
        column: TableColumn = self.cidmap.get(int(cid))
        arrow = UPARROW if column.columnsort == ASCENDING else DOWNARROW
        headertext = f"{column.headertext} {arrow}"
        self.view.heading(column.cid, text=headertext)

    # PRIVATE METHODS - WIDGET BUILDERS

    def _build_tableview_widget(self, coldata, rowdata, bootstyle):
        """Build the data table"""
        if self._searchable:
            self._build_search_frame()

        table_frame = ttk.Frame(self)
        table_frame.pack(fill=BOTH, expand=YES, side=TOP)

        self.view = ttk.Treeview(
            master=table_frame,
            columns=[x for x in range(len(coldata))],
            height=self._height,
            selectmode=EXTENDED,
            show=HEADINGS,
            bootstyle=f"{bootstyle}-table",
        )
        self.view.pack(fill=BOTH, expand=YES, side=LEFT)

        if self._yscrollbar:
            self.ybar = ttk.Scrollbar(
                master=table_frame, command=self.view.yview, orient=VERTICAL
            )
            self.ybar.pack(fill=Y, side=RIGHT)
            self.view.configure(yscrollcommand=self.ybar.set)

        self.hbar = ttk.Scrollbar(
            master=self, command=self.view.xview, orient=HORIZONTAL
        )
        self.hbar.pack(fill=X)
        self.view.configure(xscrollcommand=self.hbar.set)

        if self._paginated:
            self._build_pagination_frame()

        self.build_table_data(coldata, rowdata)

        self._rightclickmenu_cell = TableCellRightClickMenu(self)
        self._rightclickmenu_head = TableHeaderRightClickMenu(self)
        self._set_widget_binding()

    def _build_search_frame(self):
        """Build the search frame containing the search widgets. This
        frame is only created if `searchable=True` when creating the
        widget.
        """
        frame = ttk.Frame(self, padding=5)
        frame.pack(fill=X, side=TOP)
        ttk.Label(frame, text=MessageCatalog.translate("Search")).pack(side=LEFT, padx=5)
        searchterm = ttk.Entry(frame, textvariable=self._searchcriteria)
        searchterm.pack(fill=X, side=LEFT, expand=YES)
        searchterm.bind("<Return>", self._search_table_data)
        searchterm.bind("<KP_Enter>", self._search_table_data)
        if not self._paginated:
            ttk.Button(
                frame,
                text=MessageCatalog.translate("⎌"),
                command=self.reset_table,
                style="symbol.Link.TButton",
            ).pack(side=LEFT)

    def _build_pagination_frame(self):
        """Build the frame containing the pagination widgets. This
        frame is only built if `pagination=True` when creating the
        widget.
        """
        pageframe = ttk.Frame(self)
        pageframe.pack(fill=X, anchor=N)

        ttk.Button(
            pageframe,
            text=MessageCatalog.translate("⎌"),
            command=self.reset_table,
            style="symbol.Link.TButton",
        ).pack(side=RIGHT)

        ttk.Separator(pageframe, orient=VERTICAL).pack(side=RIGHT, padx=10)

        ttk.Button(
            master=pageframe,
            text="»",
            command=self.goto_last_page,
            style="symbol.Link.TButton",
        ).pack(side=RIGHT, fill=Y)
        ttk.Button(
            master=pageframe,
            text="›",
            command=self.goto_next_page,
            style="symbol.Link.TButton",
        ).pack(side=RIGHT, fill=Y)

        ttk.Button(
            master=pageframe,
            text="‹",
            command=self.goto_prev_page,
            style="symbol.Link.TButton",
        ).pack(side=RIGHT, fill=Y)
        ttk.Button(
            master=pageframe,
            text="«",
            command=self.goto_first_page,
            style="symbol.Link.TButton",
        ).pack(side=RIGHT, fill=Y)

        ttk.Separator(pageframe, orient=VERTICAL).pack(side=RIGHT, padx=10)

        lbl = ttk.Label(pageframe, textvariable=self._pagelimit)
        lbl.pack(side=RIGHT, padx=(0, 5))
        ttk.Label(pageframe, text=MessageCatalog.translate("of")).pack(side=RIGHT, padx=(5, 0))

        index = ttk.Entry(pageframe, textvariable=self._pageindex, width=4)
        index.pack(side=RIGHT)
        index.bind("<Return>", self.goto_page, "+")
        index.bind("<KP_Enter>", self.goto_page, "+")

        ttk.Label(pageframe, text=MessageCatalog.translate("Page")).pack(side=RIGHT, padx=5)

    def _build_table_rows(self, rowdata):
        """Build, load, and configure the DataTableRow objects

        Parameters:

            rowdata (List):
                An iterable of row data
        """
        for row in rowdata:
            self.insert_row(END, row)

    def _build_table_columns(self, coldata):
        """Build, load, and configure the DataTableColumn objects

        Parameters:

            coldata (List[str|Dict[str, Any]]):
                An iterable of column names or a dictionary of column
                configuration settings.
        """
        for cid, col in enumerate(coldata):
            if isinstance(col, str):
                self.tablecolumns.append(
                    TableColumn(
                        tableview=self,
                        cid=cid,
                        text=col,
                    )
                )
            else:
                if "text" not in col:
                    col["text"] = f"Column {cid}"
                self.tablecolumns.append(
                    TableColumn(tableview=self, cid=cid, **col)
                )

    # PRIVATE METHODS - WIDGET BINDING

    def _set_widget_binding(self):
        """Setup the widget binding"""
        self.view.bind("<Double-Button-1>", self._header_double_leftclick)
        self.view.bind("<Button-1>", self._header_leftclick)
        if self.tk.call("tk", "windowingsystem") == "aqua":
            sequence = "<Button-2>"
        else:
            sequence = "<Button-3>"
        self.view.bind(sequence, self._table_rightclick)

        # add trace to track pagesize changes
        self._pagesize.trace_add("write", self._trace_pagesize)

    # def _select_pagesize(self, event):
    #     cbo: ttk.Combobox = self.nametowidget(event.widget)
    #     cbo.select_clear()
    #     self.goto_first_page()

    def _trace_pagesize(self, *_):
        """Callback for changes to page size"""
        self.goto_first_page()

    def _header_double_leftclick(self, event):
        """Callback for double-click events on the tableview header"""
        region = self.view.identify_region(event.x, event.y)
        if region == "separator":
            self.autofit_columns()

    def _header_leftclick(self, event):
        """Callback for left-click events"""
        region = self.view.identify_region(event.x, event.y)
        if region == "heading":
            self.sort_column_data(event)

    def _table_rightclick(self, event):
        """Callback for right-click events"""
        region = self.view.identify_region(event.x, event.y)
        if region == "heading":
            self._rightclickmenu_head.tk_popup(event)
        elif region != "separator":
            self._rightclickmenu_cell.tk_popup(event)

cidmap property

A map of cid to tablecolumn object

iidmap property

A map of iid to tablerow object

is_filtered property

Indicates whether the table is currently filtered

pagesize property writable

The number of records visible on a single page

searchcriteria property writable

The criteria used to filter the records when the search method is invoked

tablecolumns property

A list of table column objects

tablecolumns_visible property

A list of visible table column objects

tablerows property

A list of all tablerow objects

tablerows_filtered property

A list of filtered tablerow objects

tablerows_visible property

A list of visible tablerow objects

__init__(master=None, bootstyle=DEFAULT, coldata=[], rowdata=[], paginated=False, searchable=False, yscrollbar=False, autofit=False, autoalign=True, stripecolor=None, pagesize=10, height=10, delimiter=',')

Parameters:

master (Widget):
    The parent widget.

bootstyle (str):
    A style keyword used to set the focus color of the entry
    and the background color of the date button. Available
    options include -> primary, secondary, success, info,
    warning, danger, dark, light.

coldata (List[str | Dict]):
    An iterable containing either the heading name or a
    dictionary of column settings. Configurable settings
    include >> text, image, command, anchor, width, minwidth,
    maxwidth, stretch. Also see `Tableview.insert_column`.

rowdata (List):
    An iterable of row data. The lenth of each row of data
    must match the number of columns. Also see
    `Tableview.insert_row`.

paginated (bool):
    Specifies that the data is to be paginated. A pagination
    frame will be created below the table with controls that
    enable the user to page forward and backwards in the
    data set.

pagesize (int):
    When `paginated=True`, this specifies the number of rows
    to show per page.

searchable (bool):
    If `True`, a searchbar will be created above the table.
    Press the <Return> key to initiate a search. Searching
    with an empty string will reset the search criteria, or
    pressing the reset button to the right of the search
    bar. Currently, the search method looks for any row
    that contains the search text. The filtered results
    are displayed in the table view.

yscrollbar (bool):
    If `True`, a vertical scrollbar will be created to the right
    of the table.

autofit (bool):
    If `True`, the table columns will be automatically sized
    when loaded based on the records in the current view.
    Also see `Tableview.autofit_columns`.

autoalign (bool):
    If `True`, the column headers and data are automatically
    aligned. Numbers and number headers are right-aligned
    and all other data types are left-aligned. The auto
    align method evaluates the first record in each column
    to determine the data type for alignment. Also see
    `Tableview.autoalign_columns`.

stripecolor (Tuple[str, str]):
    If provided, even numbered rows will be color using the
    (background, foreground) specified. You may specify one
    or the other by passing in **None**. For example,
    `stripecolor=('green', None)` will set the stripe
    background as green, but the foreground will remain as
    default. You may use standand color names, hexadecimal
    color codes, or bootstyle color keywords. For example,
    ('light', '#222') will set the background to the "light"
    themed ttkbootstrap color and the foreground to the
    specified hexadecimal color. Also see
    `Tableview.apply_table_stripes`.

height (int):
    Specifies how many rows will appear in the table's viewport.
    If the number of records extends beyond the table height,
    the user may use the mousewheel or scrollbar to navigate
    the data.

delimiter (str):
    The character to use as a delimiter when exporting data
    to CSV.
Source code in src/ttkbootstrap/tableview.py
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
def __init__(
        self,
        master=None,
        bootstyle=DEFAULT,
        coldata=[],
        rowdata=[],
        paginated=False,
        searchable=False,
        yscrollbar=False,
        autofit=False,
        autoalign=True,
        stripecolor=None,
        pagesize=10,
        height=10,
        delimiter=",",
):
    """
    Parameters:

        master (Widget):
            The parent widget.

        bootstyle (str):
            A style keyword used to set the focus color of the entry
            and the background color of the date button. Available
            options include -> primary, secondary, success, info,
            warning, danger, dark, light.

        coldata (List[str | Dict]):
            An iterable containing either the heading name or a
            dictionary of column settings. Configurable settings
            include >> text, image, command, anchor, width, minwidth,
            maxwidth, stretch. Also see `Tableview.insert_column`.

        rowdata (List):
            An iterable of row data. The lenth of each row of data
            must match the number of columns. Also see
            `Tableview.insert_row`.

        paginated (bool):
            Specifies that the data is to be paginated. A pagination
            frame will be created below the table with controls that
            enable the user to page forward and backwards in the
            data set.

        pagesize (int):
            When `paginated=True`, this specifies the number of rows
            to show per page.

        searchable (bool):
            If `True`, a searchbar will be created above the table.
            Press the <Return> key to initiate a search. Searching
            with an empty string will reset the search criteria, or
            pressing the reset button to the right of the search
            bar. Currently, the search method looks for any row
            that contains the search text. The filtered results
            are displayed in the table view.

        yscrollbar (bool):
            If `True`, a vertical scrollbar will be created to the right
            of the table.

        autofit (bool):
            If `True`, the table columns will be automatically sized
            when loaded based on the records in the current view.
            Also see `Tableview.autofit_columns`.

        autoalign (bool):
            If `True`, the column headers and data are automatically
            aligned. Numbers and number headers are right-aligned
            and all other data types are left-aligned. The auto
            align method evaluates the first record in each column
            to determine the data type for alignment. Also see
            `Tableview.autoalign_columns`.

        stripecolor (Tuple[str, str]):
            If provided, even numbered rows will be color using the
            (background, foreground) specified. You may specify one
            or the other by passing in **None**. For example,
            `stripecolor=('green', None)` will set the stripe
            background as green, but the foreground will remain as
            default. You may use standand color names, hexadecimal
            color codes, or bootstyle color keywords. For example,
            ('light', '#222') will set the background to the "light"
            themed ttkbootstrap color and the foreground to the
            specified hexadecimal color. Also see
            `Tableview.apply_table_stripes`.

        height (int):
            Specifies how many rows will appear in the table's viewport.
            If the number of records extends beyond the table height,
            the user may use the mousewheel or scrollbar to navigate
            the data.

        delimiter (str):
            The character to use as a delimiter when exporting data
            to CSV.
    """
    super().__init__(master)
    self._tablecols = []
    self._tablerows = []
    self._tablerows_filtered = []
    self._viewdata = []
    self._rowindex = tk.IntVar(value=0)
    self._pageindex = tk.IntVar(value=1)
    self._pagelimit = tk.IntVar(value=0)
    self._height = height
    self._pagesize = tk.IntVar(value=pagesize)
    self._paginated = paginated
    self._searchable = searchable
    self._yscrollbar = yscrollbar
    self._stripecolor = stripecolor
    self._autofit = autofit
    self._autoalign = autoalign
    self._filtered = False
    self._sorted = False
    self._searchcriteria = tk.StringVar()
    self._rightclickmenu_cell = None
    self._delimiter = delimiter
    self._iidmap = {}  # maps iid to row object
    self._cidmap = {}  # maps cid to col object

    self.view: ttk.Treeview = None
    self._build_tableview_widget(coldata, rowdata, bootstyle)

align_column_center(event=None, cid=None)

Center align the column text. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
def align_column_center(self, event=None, cid=None):
    """Center align the column text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the column relative to the original data set.

    Parameters:

        event (Event):
            An application event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.column(eo.column.cid, anchor=CENTER)
    elif cid is not None:
        self.view.column(cid, anchor=CENTER)

align_column_left(event=None, cid=None)

Left align the column text. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application click event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
def align_column_left(self, event=None, cid=None):
    """Left align the column text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the column relative to the original data set.

    Parameters:

        event (Event):
            An application click event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.column(eo.column.cid, anchor=W)
    elif cid is not None:
        self.view.column(cid, anchor=W)

align_column_right(event=None, cid=None)

Right align the column text. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
def align_column_right(self, event=None, cid=None):
    """Right align the column text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the column relative to the original data set.

    Parameters:

        event (Event):
            An application event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.column(eo.column.cid, anchor=E)
    elif cid is not None:
        self.view.column(cid, anchor=E)

align_heading_center(event=None, cid=None)

Center align the heading text. This can be triggered by either an event, or by passing in the cid, which is the index of the heading relative to the original data set.

Parameters:

event (Event):
    An application event.

cid (int):
    A unique heading identifier; typically the index of the
    heading relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
def align_heading_center(self, event=None, cid=None):
    """Center align the heading text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the heading relative to the original data set.

    Parameters:

        event (Event):
            An application event.

        cid (int):
            A unique heading identifier; typically the index of the
            heading relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.heading(eo.column.cid, anchor=CENTER)
    elif cid is not None:
        self.view.heading(cid, anchor=CENTER)

align_heading_left(event=None, cid=None)

Left align the heading text. This can be triggered by either an event, or by passing in the cid, which is the index of the heading relative to the original data set.

Parameters:

event (Event):
    An application event.

cid (int):
    A unique heading identifier; typically the index of the
    heading relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
def align_heading_left(self, event=None, cid=None):
    """Left align the heading text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the heading relative to the original data set.

    Parameters:

        event (Event):
            An application event.

        cid (int):
            A unique heading identifier; typically the index of the
            heading relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.heading(eo.column.cid, anchor=W)
    elif cid is not None:
        self.view.heading(cid, anchor=W)

align_heading_right(event=None, cid=None)

Right align the heading text. This can be triggered by either an event, or by passing in the cid, which is the index of the heading relative to the original data set.

Parameters:

event (Event):
    An application event.

cid (int):
    A unique heading identifier; typically the index of the
    heading relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
def align_heading_right(self, event=None, cid=None):
    """Right align the heading text. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the heading relative to the original data set.

    Parameters:

        event (Event):
            An application event.

        cid (int):
            A unique heading identifier; typically the index of the
            heading relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        self.view.heading(eo.column.cid, anchor=E)
    elif cid is not None:
        self.view.heading(cid, anchor=E)

apply_table_stripes(stripecolor)

Add stripes to even-numbered table rows as indicated by the stripecolor of (background, foreground). Either element may be specified as None, but both elements must be present.

Parameters:

stripecolor (Tuple[str, str]):
    A tuple of colors to apply to the table stripe. The
    tuple represents (background, foreground).
Source code in src/ttkbootstrap/tableview.py
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
def apply_table_stripes(self, stripecolor):
    """Add stripes to even-numbered table rows as indicated by the
    `stripecolor` of (background, foreground). Either element may be
    specified as `None`, but both elements must be present.

    Parameters:

        stripecolor (Tuple[str, str]):
            A tuple of colors to apply to the table stripe. The
            tuple represents (background, foreground).
    """
    style: ttk.Style = ttk.Style.get_instance()
    colors = style.colors
    if len(stripecolor) == 2:
        self._stripecolor = stripecolor
        bg, fg = stripecolor
        kw = {}
        if bg is None:
            kw["background"] = colors.active
        else:
            kw["background"] = bg
        if fg is None:
            kw["foreground"] = colors.inputfg
        else:
            kw["foreground"] = fg
        self.view.tag_configure("striped", **kw)

autoalign_columns()

Align the columns and headers based on the data type of the values. Text is left-aligned; numbers are right-aligned. This method will have no effect if there is no data in the tables.

Source code in src/ttkbootstrap/tableview.py
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
def autoalign_columns(self):
    """Align the columns and headers based on the data type of the
    values. Text is left-aligned; numbers are right-aligned. This
    method will have no effect if there is no data in the tables."""
    if len(self._tablerows) == 0:
        return

    values = self._tablerows[0]._values
    for i, value in enumerate(values):
        if str(value).isnumeric():
            self.view.column(i, anchor=E)
            self.view.heading(i, anchor=E)
        else:
            self.view.column(i, anchor=W)
            self.view.heading(i, anchor=W)

autofit_columns()

Autofit all columns in the current view

Source code in src/ttkbootstrap/tableview.py
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
def autofit_columns(self):
    """Autofit all columns in the current view"""
    f = font.nametofont("TkDefaultFont")
    pad = utility.scale_size(self, 20)
    col_widths = []

    # measure header sizes
    for col in self.tablecolumns:
        width = f.measure(f"{col._headertext} {DOWNARROW}") + pad
        col_widths.append(width)

    for row in self.tablerows_visible:
        values = row.values
        for i, value in enumerate(values):
            old_width = col_widths[i]
            new_width = f.measure(str(value)) + pad
            width = max(old_width, new_width)
            col_widths[i] = width

    for i, width in enumerate(col_widths):
        self.view.column(i, width=width)

build_table_data(coldata, rowdata)

Insert the specified column and row data.

The coldata can be either a string column name or a dictionary of column settings that are passed to the insert_column method. You may use a mixture of string and dictionary in the list of coldata.

!!!warning "Existing table data will be erased. This method will completely rebuild the underlying table with the new column and row data. Any existing data will be lost.

Parameters:

coldata (List[Union[str, Dict]]):
    An iterable of column names and/or settings.

rowdata (List):
    An iterable of row values.
Source code in src/ttkbootstrap/tableview.py
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
def build_table_data(self, coldata, rowdata):
    """Insert the specified column and row data.

    The coldata can be either a string column name or a dictionary
    of column settings that are passed to the `insert_column`
    method. You may use a mixture of string and dictionary in
    the list of coldata.

    !!!warning "Existing table data will be erased.
        This method will completely rebuild the underlying table
        with the new column and row data. Any existing data will
        be lost.

    Parameters:

        coldata (List[Union[str, Dict]]):
            An iterable of column names and/or settings.

        rowdata (List):
            An iterable of row values.
    """
    # destroy the existing data if existing
    self.purge_table_data()

    # build the table columns
    for i, col in enumerate(coldata):
        if isinstance(col, str):
            # just a column name
            self.insert_column(i, col)
        else:
            # a dictionary of column settings
            self.insert_column(i, **col)

    # build the table rows
    for values in rowdata:
        self.insert_row(values=values)

    # load the table data
    self.load_table_data()

    # apply table formatting
    if self._autofit:
        self.autofit_columns()

    if self._autoalign:
        self.autoalign_columns()

    if self._stripecolor is not None:
        self.apply_table_stripes(self._stripecolor)

    self.goto_first_page()

configure(cnf=None, **kwargs)

Configure the internal Treeview widget. If cnf is provided, value of the option is return. Otherwise the widget is configured via kwargs.

Parameters:

cnf (Any):
    An option to query.

**kwargs (Dict):
    Optional keyword arguments used to configure the internal
    Treeview widget.

Returns:

Union[Any, None]:
    The value of cnf or None.
Source code in src/ttkbootstrap/tableview.py
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
def configure(self, cnf=None, **kwargs) -> Union[Any, None]:
    """Configure the internal `Treeview` widget. If cnf is provided,
    value of the option is return. Otherwise the widget is
    configured via kwargs.

    Parameters:

        cnf (Any):
            An option to query.

        **kwargs (Dict):
            Optional keyword arguments used to configure the internal
            Treeview widget.

    Returns:

        Union[Any, None]:
            The value of cnf or None.
    """
    try:
        if "pagesize" in kwargs:
            pagesize: int = kwargs.pop("pagesize")
            self._pagesize.set(value=pagesize)

        self.view.configure(cnf, **kwargs)
    except:
        super().configure(cnf, **kwargs)

delete_column(index=None, cid=None, visible=True)

Delete the specified column based on the column index or the unique cid.

Unless otherwise specified, the index refers to the column index as displayed in the tableview.

If cid is provided, the column associated with the cid is deleted regardless of whether it is in the visible data sets.

Parameters:

index (int):
    The numerical index of the column.

cid (str):
    A unique column indentifier.

visible (bool):
    Specifies that the index should refer to the visible
    columns. Otherwise, if False, the original column
    position is used.
Source code in src/ttkbootstrap/tableview.py
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
def delete_column(self, index=None, cid=None, visible=True):
    """Delete the specified column based on the column index or the
    unique cid.

    Unless otherwise specified, the index refers to the column index
    as displayed in the tableview.

    If cid is provided, the column associated with the cid is deleted
    regardless of whether it is in the visible data sets.

    Parameters:

        index (int):
            The numerical index of the column.

        cid (str):
            A unique column indentifier.

        visible (bool):
            Specifies that the index should refer to the visible
            columns. Otherwise, if False, the original column
            position is used.
    """
    if cid is not None:
        column: TableColumn = self.cidmap(int(cid))
        column.delete()

    elif index is not None and visible:
        self.tablecolumns_visible[int(index)].delete()

    elif index is None and not visible:
        self.tablecolumns[int(index)].delete()

delete_columns(indices=None, cids=None, visible=True)

Delete columns specified by indices or cids.

Unless specified otherwise, the index refers to the position of the columns in the table from left to right starting with index 0.

!!!Warning "Use this method with caution! This method may or may not suffer performance issues. Internally, this method calls the delete_column method on each column specified in the list. The delete_column method deletes the related column from each record in the table data. So, if there are a lot of records this could be problematic. It may be more beneficial to use the build_table_data if you plan on changing the structure of the table dramatically.

Parameters:

indices (List[int]):
    A list of column indices to delete from the table.

cids (List[str]):
    A list of unique column identifiers to delete from the
    table.

visible (bool):
    If True, the index refers to the visible position of the
    column in the stable, from left to right starting at
    index 0.
Source code in src/ttkbootstrap/tableview.py
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
def delete_columns(self, indices=None, cids=None, visible=True):
    """Delete columns specified by indices or cids.

    Unless specified otherwise, the index refers to the position
    of the columns in the table from left to right starting with
    index 0.

    !!!Warning "Use this method with caution!
        This method may or may not suffer performance issues.
        Internally, this method calls the `delete_column` method
        on each column specified in the list. The `delete_column`
        method deletes the related column from each record in
        the table data. So, if there are a lot of records this
        could be problematic. It may be more beneficial to use
        the `build_table_data` if you plan on changing the
        structure of the table dramatically.

    Parameters:

        indices (List[int]):
            A list of column indices to delete from the table.

        cids (List[str]):
            A list of unique column identifiers to delete from the
            table.

        visible (bool):
            If True, the index refers to the visible position of the
            column in the stable, from left to right starting at
            index 0.
    """
    if cids is not None:
        for cid in cids:
            self.delete_column(cid=cid)
    elif indices is not None:
        for index in indices:
            self.delete_column(index=index, visible=visible)

delete_row(index=None, iid=None, visible=True)

Delete a record from the data set.

Unless specified otherwise, the index refers to the record position within the visible data set from top to bottom starting with index 0.

If iid is provided, the record associated with the cid is deleted regardless of whether it is in the visible data set.

Parameters:

index (int):
    The numerical index of the record within the data set.

iid (str):
    A unique record identifier.

visible (bool):
    Indicates that the record index is relative to the current
    records in view, otherwise, the original data set index is
    used if False.
Source code in src/ttkbootstrap/tableview.py
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
def delete_row(self, index=None, iid=None, visible=True):
    """Delete a record from the data set.

    Unless specified otherwise, the index refers to the record
    position within the visible data set from top to bottom
    starting with index 0.

    If iid is provided, the record associated with the cid is deleted
    regardless of whether it is in the visible data set.

    Parameters:

        index (int):
            The numerical index of the record within the data set.

        iid (str):
            A unique record identifier.

        visible (bool):
            Indicates that the record index is relative to the current
            records in view, otherwise, the original data set index is
            used if False.
    """
    # delete from iid
    if iid is not None:
        record: TableRow = self.iidmap.get(iid)
        record.delete()
    elif index is not None:
        # visible index
        if visible:
            record = self.tablerows_visible[index]
            record.delete()
        # original index
        else:
            for record in self.tablerows:
                if record._sort == index:
                    record.delete()

delete_rows(indices=None, iids=None, visible=True)

Delete rows specified by indices or iids.

If both indices and iids are None, then all records in the table will be deleted.

Source code in src/ttkbootstrap/tableview.py
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
def delete_rows(self, indices=None, iids=None, visible=True):
    """Delete rows specified by indices or iids.

    If both indices and iids are None, then all records in the
    table will be deleted.
    """
    # remove records by iid
    if iids is not None:
        for iid in iids:
            self.delete_row(iid=iid)
    # remove records by index
    elif indices is not None:
        for index in indices:
            self.delete_row(index=index, visible=visible)
    # remove ALL records
    else:
        self._tablerows.clear()
        self._tablerows_filtered.clear()
        self._viewdata.clear()
        self._iidmap.clear()
        records = self.view.get_children()
        self.view.delete(*records)
    # route to new page if no records visible
    if len(self._viewdata) == 0:
        self.goto_page()

export_all_records()

Export all records to a csv file

Source code in src/ttkbootstrap/tableview.py
1553
1554
1555
1556
1557
def export_all_records(self):
    """Export all records to a csv file"""
    headers = [col.headertext for col in self.tablecolumns]
    records = [row.values for row in self.tablerows]
    self.save_data_to_csv(headers, records, self._delimiter)

export_current_page()

Export records on current page to csv file

Source code in src/ttkbootstrap/tableview.py
1559
1560
1561
1562
1563
def export_current_page(self):
    """Export records on current page to csv file"""
    headers = [col.headertext for col in self.tablecolumns]
    records = [row.values for row in self.tablerows_visible]
    self.save_data_to_csv(headers, records, self._delimiter)

export_current_selection()

Export rows currently selected to csv file

Source code in src/ttkbootstrap/tableview.py
1565
1566
1567
1568
1569
1570
1571
1572
1573
def export_current_selection(self):
    """Export rows currently selected to csv file"""
    headers = [col.headertext for col in self.tablecolumns]
    selected = self.view.selection()
    records = []
    for iid in selected:
        record: TableRow = self.iidmap.get(iid)
        records.append(record.values)
    self.save_data_to_csv(headers, records, self._delimiter)

export_records_in_filter()

Export rows currently filtered to csv file

Source code in src/ttkbootstrap/tableview.py
1575
1576
1577
1578
1579
1580
1581
def export_records_in_filter(self):
    """Export rows currently filtered to csv file"""
    headers = [col.headertext for col in self.tablecolumns]
    if not self.is_filtered:
        return
    records = [row.values for row in self.tablerows_filtered]
    self.save_data_to_csv(headers, records, self._delimiter)

fill_empty_columns(fillvalue='')

Fill empty columns with the fillvalue.

This method can be used to fill in missing values when a column column is inserted after data has already been inserted into the tableview.

Parameters:

fillvalue (Any):
    A value to insert into an empty column
Source code in src/ttkbootstrap/tableview.py
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
def fill_empty_columns(self, fillvalue=""):
    """Fill empty columns with the fillvalue.

    This method can be used to fill in missing values when a column
    column is inserted after data has already been inserted into
    the tableview.

    Parameters:

        fillvalue (Any):
            A value to insert into an empty column
    """
    rowcount = len(self._tablerows)
    if rowcount == 0:
        return
    colcount = len(self._tablecols)
    for row in self._tablerows:
        var = colcount - len(row._values)
        if var <= 0:
            return
        else:
            for _ in range(var):
                row._values.append(fillvalue)
            row.configure(values=row._values)

filter_column_to_value(event=None, cid=None, value=None)

Hide all records except for records where the current column exactly matches the provided value. This method may be triggered by a window event or by specifying the column id.

Parameters:

event (Event):
    A window click event.

cid (int):
    A unique column identifier; typically the numerical
    index of the column within the original dataset.

value (Any):
    The criteria used to filter the column.
Source code in src/ttkbootstrap/tableview.py
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
def filter_column_to_value(self, event=None, cid=None, value=None):
    """Hide all records except for records where the current
    column exactly matches the provided value. This method may
    be triggered by a window event or by specifying the column id.

    Parameters:

        event (Event):
            A window click event.

        cid (int):
            A unique column identifier; typically the numerical
            index of the column within the original dataset.

        value (Any):
            The criteria used to filter the column.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        index = eo.column.tableindex
        value = value or eo.row.values[index]
    elif cid is not None:
        column: TableColumn = self.cidmap.get(cid)
        index = column.tableindex
    else:
        return

    self._filtered = True
    self.tablerows_filtered.clear()
    self.unload_table_data()

    for row in self.tablerows:
        if row.values[index] == value:
            self.tablerows_filtered.append(row)

    self._rowindex.set(0)
    self.load_table_data()

filter_to_selected_rows()

Hide all records except for the selected rows

Source code in src/ttkbootstrap/tableview.py
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
def filter_to_selected_rows(self):
    """Hide all records except for the selected rows"""
    criteria = self.view.selection()
    if len(criteria) == 0:
        return  # nothing is selected

    if self.is_filtered:
        for row in self.tablerows_visible:
            if row.iid not in criteria:
                row.hide()
                self.tablerows_filtered.remove(row)
    else:
        self._filtered = True
        self.tablerows_filtered.clear()
        for row in self.tablerows_visible:
            if row.iid in criteria:
                self.tablerows_filtered.append(row)
    self._rowindex.set(0)
    self.load_table_data()

get_column(index=None, visible=False, cid=None)

Returns the TableColumn object from an index or a cid.

If index is specified, the column index refers to the index within the original, unless the visible flag is set, in which case the index is relative to the visible columns in view.

If cid is specified, the column associated with the cid is return regardless of whether it is visible.

Parameters:

index (int):
    The numerical index of the column.

visible (bool):
    Use the index of the visible columns as they appear
    in the table.

Returns:

Union[TableColumn, None]:
    The table column object if found, otherwise None.
Source code in src/ttkbootstrap/tableview.py
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
def get_column(
        self, index=None, visible=False, cid=None
) -> TableColumn:
    """Returns the `TableColumn` object from an index or a cid.

    If index is specified, the column index refers to the index
    within the original, unless the visible flag is set, in which
    case the index is relative to the visible columns in view.

    If cid is specified, the column associated with the cid is
    return regardless of whether it is visible.

    Parameters:

        index (int):
            The numerical index of the column.

        visible (bool):
            Use the index of the visible columns as they appear
            in the table.

    Returns:

        Union[TableColumn, None]:
            The table column object if found, otherwise None.
    """
    if cid is not None:
        return self._cidmap.get(cid)

    if not visible:
        # original column index
        try:
            return self._tablecols[index]
        except IndexError:
            return None
    else:
        # visible column index
        cols = self.view.cget("columns")
        if len(cols) > 0:
            cols = [int(x) for x in cols]
        else:
            cols = []

        dcols = self.view.cget("displaycolumns")
        if "#all" in dcols:
            dcols = cols
        else:
            try:
                x = int(dcols[index])
                for c in self._tablecols:
                    if c.cid == x:
                        return c
            except ValueError:
                return None

get_columns()

Returns a list of all column objects. Same as using the Tableview.tablecolumns property.

Source code in src/ttkbootstrap/tableview.py
1103
1104
1105
1106
def get_columns(self) -> List[TableColumn]:
    """Returns a list of all column objects. Same as using the
    `Tableview.tablecolumns` property."""
    return self._tablecols

get_row(index=None, visible=False, filtered=False, iid=None)

Returns the TableRow object from an index or the iid.

If an index is specified, the row index refers to the index within the original dataset. When choosing a subset of data, the visible data takes priority over filtered if both flags are set.

If an iid is specified, the object attached to that iid is returned regardless of whether or not it is visible or filtered.

Parameters:

index (int):
    The numerical index of the column.

iid (str):
    A unique column identifier.

visible (bool):
    Use the index of the visible rows as they appear
    in the current table view.

filtered (bool):
    Use the index of the rows within the filtered data
    set.

Returns:

Union[TableRow, None]:
    The table column object if found, otherwise None
Source code in src/ttkbootstrap/tableview.py
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
def get_row(self, index=None, visible=False, filtered=False, iid=None) -> TableRow:
    """Returns the `TableRow` object from an index or the iid.

    If an index is specified, the row index refers to the index
    within the original dataset. When choosing a subset of data,
    the visible data takes priority over filtered if both flags
    are set.

    If an iid is specified, the object attached to that iid is
    returned regardless of whether or not it is visible or
    filtered.

    Parameters:

        index (int):
            The numerical index of the column.

        iid (str):
            A unique column identifier.

        visible (bool):
            Use the index of the visible rows as they appear
            in the current table view.

        filtered (bool):
            Use the index of the rows within the filtered data
            set.

    Returns:

        Union[TableRow, None]:
            The table column object if found, otherwise None
    """
    if iid is not None:
        return self.iidmap.get(iid)

    if visible:
        try:
            return self.tablerows_visible[index]
        except IndexError:
            return None
    elif filtered:
        try:
            return self.tablerows_filtered[index]
        except IndexError:
            return None
    else:
        try:
            return self.tablerows[index]
        except IndexError:
            return None

get_rows(visible=False, filtered=False, selected=False)

Return a list of TableRow objects.

Return a subset of rows based on optional flags. Only ONE flag can be used at a time. If more than one flag is set to True, then the first flag will be used to return the data.

Parameters:

visible (bool):
    If true, only records in the current view will be returned.

filtered (bool):
    If True, only rows in the filtered dataset will be returned.

selected (bool):
    If True, only rows that are currently selected will be returned.

Returns:

List[TableRow]:
    A list of TableRow objects.
Source code in src/ttkbootstrap/tableview.py
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
def get_rows(self, visible=False, filtered=False, selected=False) -> List[TableRow]:
    """Return a list of TableRow objects.

    Return a subset of rows based on optional flags. Only ONE flag can be used
    at a time. If more than one flag is set to `True`, then the first flag will
    be used to return the data.

    Parameters:

        visible (bool):
            If true, only records in the current view will be returned.

        filtered (bool):
            If True, only rows in the filtered dataset will be returned.

        selected (bool):
            If True, only rows that are currently selected will be returned.

    Returns:

        List[TableRow]:
            A list of TableRow objects.
    """
    if visible:
        return self._viewdata
    elif filtered:
        return self._tablerows_filtered
    elif selected:
        return [row for row in self._viewdata if row.iid in self.view.selection()]
    else:
        return self._tablerows

goto_first_page()

Update table with first page of data

Source code in src/ttkbootstrap/tableview.py
1262
1263
1264
1265
1266
def goto_first_page(self):
    """Update table with first page of data"""
    self._rowindex.set(0)
    self.load_table_data()
    self._select_first_visible_item()

goto_last_page()

Update table with the last page of data

Source code in src/ttkbootstrap/tableview.py
1268
1269
1270
1271
1272
1273
def goto_last_page(self):
    """Update table with the last page of data"""
    pagelimit = self._pagelimit.get() - 1
    self._rowindex.set(self.pagesize * pagelimit)
    self.load_table_data()
    self._select_first_visible_item()

goto_next_page()

Update table with next page of data

Source code in src/ttkbootstrap/tableview.py
1275
1276
1277
1278
1279
1280
1281
1282
def goto_next_page(self):
    """Update table with next page of data"""
    if self._pageindex.get() >= self._pagelimit.get():
        return
    rowindex = self._rowindex.get()
    self._rowindex.set(rowindex + self.pagesize)
    self.load_table_data()
    self._select_first_visible_item()

goto_page(*_)

Go to a specific page indicated by the page entry widget.

Source code in src/ttkbootstrap/tableview.py
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
def goto_page(self, *_):
    """Go to a specific page indicated by the page entry widget."""
    pagelimit = self._pagelimit.get()
    pageindex = self._pageindex.get()
    if pageindex > pagelimit:
        pageindex = pagelimit
        self._pageindex.set(pageindex)
    elif pageindex <= 0:
        pageindex = 1
        self._pageindex.set(pageindex)
    rowindex = (pageindex * self.pagesize) - self.pagesize
    self._rowindex.set(rowindex)
    self.load_table_data()
    self._select_first_visible_item()

goto_prev_page()

Update table with prev page of data

Source code in src/ttkbootstrap/tableview.py
1284
1285
1286
1287
1288
1289
1290
1291
def goto_prev_page(self):
    """Update table with prev page of data"""
    if self._pageindex.get() <= 1:
        return
    rowindex = self._rowindex.get()
    self._rowindex.set(rowindex - self.pagesize)
    self.load_table_data()
    self._select_first_visible_item()

hide_selected_column(event=None, cid=None)

Detach the selected column from the tableview. This method may be triggered by a window event or by specifying the column id.

Parameters:

event (Event):
    A window click event

cid (int):
    A unique column identifier; typically the numerical
    index of the column within the original dataset.
Source code in src/ttkbootstrap/tableview.py
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
def hide_selected_column(self, event=None, cid=None):
    """Detach the selected column from the tableview. This method
    may be triggered by a window event or by specifying the column
    id.

    Parameters:

        event (Event):
            A window click event

        cid (int):
            A unique column identifier; typically the numerical
            index of the column within the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column.hide()
    elif cid is not None:
        column: TableColumn = self.cidmap.get(cid)
        column.hide()

hide_selected_rows()

Hide the currently selected rows

Source code in src/ttkbootstrap/tableview.py
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
def hide_selected_rows(self):
    """Hide the currently selected rows"""
    selected = self.view.selection()
    view_cnt = len(self._viewdata)
    hide_cnt = len(selected)
    self.view.detach(*selected)

    tablerows = []
    for row in self.tablerows_visible:
        if row.iid in selected:
            tablerows.append(row)

    if not self.is_filtered:
        self._filtered = True
        self._tablerows_filtered = self.tablerows.copy()

    for row in tablerows:
        if self.is_filtered:
            self.tablerows_filtered.remove(row)

    if hide_cnt == view_cnt:
        # assuming that if the count of the records on the page are
        #   selected for hiding, then need to go to the next page
        # The call to `load_table_data` is duplicative, but currently
        #   this is the only way to get this to work until I've
        #   refactored this bit.
        self.load_table_data()
        self.goto_page()
    else:
        self.load_table_data()

insert_column(index, text='', image='', command='', anchor=W, width=200, minwidth=20, stretch=False)

Parameters:

index (Union[int, str]):
    A numerical index that specifieds where to insert
    the column. You may also use the string 'end' to
    insert the column in the right-most position. If the
    index exceeds the column count, it will be inserted
    at the right-most position.

text (str):
    The header text.

image (PhotoImage):
    An image that is displayed to the left of the header text.

command (Callable):
    A function called whenever the header button is clicked.

anchor (str):
    The position of the header text within the header. One
    of "e", "w", "center".

width (int):
    Specifies the width of the column in pixels.

minwidth (int):
    Specifies the minimum width of the column in pixels.

stretch (bool):
    Specifies whether or not the column width should be
    adjusted whenever the widget is resized or the user
    drags the column separator.

Returns:

TableColumn:
    A table column object.
Source code in src/ttkbootstrap/tableview.py
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
def insert_column(
        self,
        index,
        text="",
        image="",
        command="",
        anchor=W,
        width=200,
        minwidth=20,
        stretch=False,
) -> TableColumn:
    """
    Parameters:

        index (Union[int, str]):
            A numerical index that specifieds where to insert
            the column. You may also use the string 'end' to
            insert the column in the right-most position. If the
            index exceeds the column count, it will be inserted
            at the right-most position.

        text (str):
            The header text.

        image (PhotoImage):
            An image that is displayed to the left of the header text.

        command (Callable):
            A function called whenever the header button is clicked.

        anchor (str):
            The position of the header text within the header. One
            of "e", "w", "center".

        width (int):
            Specifies the width of the column in pixels.

        minwidth (int):
            Specifies the minimum width of the column in pixels.

        stretch (bool):
            Specifies whether or not the column width should be
            adjusted whenever the widget is resized or the user
            drags the column separator.

    Returns:

        TableColumn:
            A table column object.
    """
    self.reset_table()
    colcount = len(self.tablecolumns)
    cid = colcount
    if index == END:
        index = -1
    elif index > colcount - 1:
        index = -1

    # actual columns
    cols = self.view.cget("columns")
    if len(cols) > 0:
        cols = [int(x) for x in cols]
        cols.append(cid)
    else:
        cols = [cid]

    # visible columns
    dcols = self.view.cget("displaycolumns")
    if "#all" in dcols:
        dcols = cols
    elif len(dcols) > 0:
        dcols = [int(x) for x in dcols]
        if index == -1:
            dcols.append(cid)
        else:
            dcols.insert(index, cid)
    else:
        dcols = [cid]

    self.view.configure(columns=cols, displaycolumns=dcols)

    # configure new column
    column = TableColumn(
        tableview=self,
        cid=cid,
        text=text,
        image=image,
        command=command,
        anchor=anchor,
        width=width,
        minwidth=minwidth,
        stretch=stretch,
    )
    self._tablecols.append(column)
    # must be called to show the header after initially creating it
    # ad hoc, not sure why this should be the case;
    self._column_sort_header_reset()

    # update settings after they are erased when a column is
    #   inserted
    for column in self._tablecols:
        column.restore_settings()

    return column

insert_row(index=END, values=[])

Insert a row into the tableview at index.

You must call Tableview.load_table_data() to update the current view. If the data is filtered, you will need to call Tableview.load_table_data(clear_filters=True).

Parameters:

index (Union[int, str]):
    A numerical index that specifieds where to insert
    the record in the dataset. You may also use the string
    'end' to append the record to the end of the data set.
    If the index exceeds the record count, it will be
    appended to the end of the dataset.

values (Iterable):
    An iterable of values to insert into the data set.
    The number of columns implied by the list of values
    must match the number of columns in the data set for
    the values to be visible.

Returns:

TableRow:
    A table row object.
Source code in src/ttkbootstrap/tableview.py
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
def insert_row(self, index=END, values=[]) -> TableRow:
    """Insert a row into the tableview at index.

    You must call `Tableview.load_table_data()` to update the
    current view. If the data is filtered, you will need to call
    `Tableview.load_table_data(clear_filters=True)`.

    Parameters:

        index (Union[int, str]):
            A numerical index that specifieds where to insert
            the record in the dataset. You may also use the string
            'end' to append the record to the end of the data set.
            If the index exceeds the record count, it will be
            appended to the end of the dataset.

        values (Iterable):
            An iterable of values to insert into the data set.
            The number of columns implied by the list of values
            must match the number of columns in the data set for
            the values to be visible.

    Returns:

        TableRow:
            A table row object.
    """
    rowcount = len(self._tablerows)

    # validate the index
    if len(values) == 0:
        return
    if index == END:
        index = -1
    elif index > rowcount - 1:
        index = -1

    record = TableRow(self, values)
    if rowcount == 0 or index == -1:
        self._tablerows.append(record)
    else:
        self._tablerows.insert(index, record)

    return record

insert_rows(index, rowdata)

Insert row after index for each row in *row. If index does not exist then the records are appended to the end of the table. You can also use the string 'end' to append records at the end of the table.

Parameters:

index (Union[int, str]):
    The location in the data set after where the records
    will be inserted. You may use a numerical index or
    the string 'end', which will append the records to the
    end of the data set.

rowdata (List[Any, List]):
    A list of row values to be inserted into the table.

Examples:

```python
Tableview.insert_rows('end', ['one', 1], ['two', 2])
```
Source code in src/ttkbootstrap/tableview.py
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
def insert_rows(self, index, rowdata):
    """Insert row after index for each row in *row. If index does
    not exist then the records are appended to the end of the table.
    You can also use the string 'end' to append records at the end
    of the table.

    Parameters:

        index (Union[int, str]):
            The location in the data set after where the records
            will be inserted. You may use a numerical index or
            the string 'end', which will append the records to the
            end of the data set.

        rowdata (List[Any, List]):
            A list of row values to be inserted into the table.

    Examples:

        ```python
        Tableview.insert_rows('end', ['one', 1], ['two', 2])
        ```
    """
    if len(rowdata) == 0:
        return
    for values in reversed(rowdata):
        self.insert_row(index, values)

load_table_data(clear_filters=False)

Load records into the tableview.

Parameters:

clear_filters (bool):
    Specifies that the table filters should be cleared
    before loading the data into the view.
Source code in src/ttkbootstrap/tableview.py
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
def load_table_data(self, clear_filters=False):
    """Load records into the tableview.

    Parameters:

        clear_filters (bool):
            Specifies that the table filters should be cleared
            before loading the data into the view.
    """
    if len(self.tablerows) == 0:
        return

    if clear_filters:
        self.reset_table()

    self.unload_table_data()

    if self._paginated:
        page_start = self._rowindex.get()
        page_end = self._rowindex.get() + self._pagesize.get()
    else:
        page_start = 0
        page_end = len(self._tablerows)

    if self._filtered:
        rowdata = self._tablerows_filtered[page_start:page_end]
        rowcount = len(self._tablerows_filtered)
    else:
        rowdata = self._tablerows[page_start:page_end]
        rowcount = len(self._tablerows)

    self._pagelimit.set(ceil(rowcount / self._pagesize.get()))

    pageindex = ceil(page_end / self._pagesize.get())
    pagelimit = self._pagelimit.get()
    self._pageindex.set(min([pagelimit, pageindex]))

    for i, row in enumerate(rowdata):
        if self._stripecolor is not None and i % 2 == 0:
            row.show(True)
        else:
            row.show(False)
        self._viewdata.append(row)

move_column_left(event=None, cid=None)

Move column one position to the left. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application click event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
def move_column_left(self, event=None, cid=None):
    """Move column one position to the left. This can be triggered
    by either an event, or by passing in the `cid`, which is the
    index of the column relative to the original data set.

    Parameters:

        event (Event):
            An application click event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column
    elif cid is not None:
        column = self.cidmap.get(cid)
    else:
        return

    displaycols = [x.cid for x in self.tablecolumns_visible]
    old_index = column.displayindex
    if old_index == 0:
        return

    new_index = column.displayindex - 1
    displaycols.insert(new_index, displaycols.pop(old_index))
    self.view.configure(displaycolumns=displaycols)

move_column_right(event=None, cid=None)

Move column one position to the right. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application click event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
def move_column_right(self, event=None, cid=None):
    """Move column one position to the right. This can be triggered
    by either an event, or by passing in the `cid`, which is the
    index of the column relative to the original data set.

    Parameters:

        event (Event):
            An application click event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column
    elif cid is not None:
        column = self.cidmap.get(cid)
    else:
        return

    displaycols = [x.cid for x in self.tablecolumns_visible]
    old_index = column.displayindex
    if old_index == len(displaycols) - 1:
        return

    new_index = old_index + 1
    displaycols.insert(new_index, displaycols.pop(old_index))
    self.view.configure(displaycolumns=displaycols)

move_column_to_first(event=None, cid=None)

Move column to leftmost position. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application click event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
def move_column_to_first(self, event=None, cid=None):
    """Move column to leftmost position. This can be triggered by
    either an event, or by passing in the `cid`, which is the index
    of the column relative to the original data set.

    Parameters:

        event (Event):
            An application click event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column
    elif cid is not None:
        column = self.cidmap.get(cid)
    else:
        return

    displaycols = [x.cid for x in self.tablecolumns_visible]
    old_index = column.displayindex
    if old_index == 0:
        return

    displaycols.insert(0, displaycols.pop(old_index))
    self.view.configure(displaycolumns=displaycols)

move_column_to_last(event=None, cid=None)

Move column to the rightmost position. This can be triggered by either an event, or by passing in the cid, which is the index of the column relative to the original data set.

Parameters:

event (Event):
    An application click event.

cid (int):
    A unique column identifier; typically the index of the
    column relative to the original dataset.
Source code in src/ttkbootstrap/tableview.py
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
def move_column_to_last(self, event=None, cid=None):
    """Move column to the rightmost position. This can be triggered
    by either an event, or by passing in the `cid`, which is the
    index of the column relative to the original data set.

    Parameters:

        event (Event):
            An application click event.

        cid (int):
            A unique column identifier; typically the index of the
            column relative to the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column
    elif cid is not None:
        column = self.cidmap.get(cid)
    else:
        return

    displaycols = [x.cid for x in self.tablecolumns_visible]
    old_index = column.displayindex
    if old_index == len(displaycols) - 1:
        return

    new_index = len(displaycols) - 1
    displaycols.insert(new_index, displaycols.pop(old_index))
    self.view.configure(displaycolumns=displaycols)

move_row_down()

Move the selected rows down one position in the dataset

Source code in src/ttkbootstrap/tableview.py
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
def move_row_down(self):
    """Move the selected rows down one position in the dataset"""
    selected = self.view.selection()
    if len(selected) == 0:
        return

    if self._filtered:
        tablerows = self._tablerows_filtered
    else:
        tablerows = self._tablerows

    for iid in selected:
        row = self.iidmap.get(iid)
        index = tablerows.index(row) + 1
        tablerows.remove(row)
        tablerows.insert(index, row)

    if self._filtered:
        self._tablerows_filtered = tablerows
    else:
        self._tablerows = tablerows

    # refresh the table data
    self.unload_table_data()
    self.load_table_data()

move_selected_row_up()

Move the selected rows up one position in the dataset

Source code in src/ttkbootstrap/tableview.py
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
def move_selected_row_up(self):
    """Move the selected rows up one position in the dataset"""
    selected = self.view.selection()
    if len(selected) == 0:
        return

    if self.is_filtered:
        tablerows = self._tablerows_filtered.copy()
    else:
        tablerows = self.tablerows.copy()

    for iid in selected:
        row = self.iidmap.get(iid)
        index = tablerows.index(row) - 1
        tablerows.remove(row)
        tablerows.insert(index, row)

    if self.is_filtered:
        self._tablerows_filtered = tablerows
    else:
        self._tablerows = tablerows

    # refresh the table data
    self.unload_table_data()
    self.load_table_data()

move_selected_rows_to_bottom()

Move the selected rows to the bottom of the dataset

Source code in src/ttkbootstrap/tableview.py
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
def move_selected_rows_to_bottom(self):
    """Move the selected rows to the bottom of the dataset"""
    selected = self.view.selection()
    if len(selected) == 0:
        return

    if self.is_filtered:
        tablerows = self.tablerows_filtered.copy()
    else:
        tablerows = self.tablerows.copy()

    for iid in selected:
        row = self.iidmap.get(iid)
        tablerows.remove(row)
        tablerows.append(row)

    if self.is_filtered:
        self._tablerows_filtered = tablerows
    else:
        self._tablerows = tablerows

    # refresh the table data
    self.unload_table_data()
    self.load_table_data()

move_selected_rows_to_top()

Move the selected rows to the top of the data set

Source code in src/ttkbootstrap/tableview.py
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
def move_selected_rows_to_top(self):
    """Move the selected rows to the top of the data set"""
    selected = self.view.selection()
    if len(selected) == 0:
        return

    if self.is_filtered:
        tablerows = self.tablerows_filtered.copy()
    else:
        tablerows = self.tablerows.copy()

    for i, iid in enumerate(selected):
        row = self.iidmap.get(iid)
        tablerows.remove(row)
        tablerows.insert(i, row)

    if self.is_filtered:
        self._tablerows_filtered = tablerows
    else:
        self._tablerows = tablerows

    # refresh the table data
    self.unload_table_data()
    self.load_table_data()

purge_table_data()

Erase all table and column data.

This method will completely destroy the table data structure. The table will need to be completely rebuilt after using this method.

Source code in src/ttkbootstrap/tableview.py
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
def purge_table_data(self):
    """Erase all table and column data.

    This method will completely destroy the table data structure.
    The table will need to be completely rebuilt after using this
    method.
    """
    self.delete_rows()
    self.cidmap.clear()
    self.tablecolumns.clear()
    self.view.configure(columns=[], displaycolumns=[])

reset_column_filters()

Remove all column level filters; unhide all columns.

Source code in src/ttkbootstrap/tableview.py
1386
1387
1388
1389
def reset_column_filters(self):
    """Remove all column level filters; unhide all columns."""
    cols = [col.cid for col in self.tablecolumns]
    self.view.configure(displaycolumns=cols)

reset_column_sort()

Display all columns by original insert index

Source code in src/ttkbootstrap/tableview.py
1395
1396
1397
1398
def reset_column_sort(self):
    """Display all columns by original insert index"""
    cols = sorted([col.cid for col in self.tablecolumns_visible], key=int)
    self.view.configure(displaycolumns=cols)

reset_row_filters()

Remove all row level filters; unhide all rows.

Source code in src/ttkbootstrap/tableview.py
1379
1380
1381
1382
1383
1384
def reset_row_filters(self):
    """Remove all row level filters; unhide all rows."""
    self._filtered = False
    self.searchcriteria = ""
    self.unload_table_data()
    self.load_table_data()

reset_row_sort()

Display all table rows by original insert index

Source code in src/ttkbootstrap/tableview.py
1391
1392
1393
def reset_row_sort(self):
    """Display all table rows by original insert index"""
    ...

reset_table()

Remove all table data filters and column sorts

Source code in src/ttkbootstrap/tableview.py
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
def reset_table(self):
    """Remove all table data filters and column sorts"""
    self._filtered = False
    self.searchcriteria = ""
    try:
        sortedrows = sorted(self.tablerows, key=lambda x: x._sort)
    except IndexError:
        self.fill_empty_columns()
        sortedrows = sorted(self.tablerows, key=lambda x: x._sort)
    self._tablerows = sortedrows
    self.unload_table_data()

    # reset the columns
    self.reset_column_filters()
    self.reset_column_sort()

    self._column_sort_header_reset()
    self.goto_first_page()  # needed?

save_data_to_csv(headers, records, delimiter=',')

Save data records to a csv file.

Parameters:

headers (List[str]):
    A list of header labels.

records (List[Tuple[...]]):
    A list of table records.

delimiter (str):
    The character to use for delimiting the values.
Source code in src/ttkbootstrap/tableview.py
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
def save_data_to_csv(self, headers, records, delimiter=","):
    """Save data records to a csv file.

    Parameters:

        headers (List[str]):
            A list of header labels.

        records (List[Tuple[...]]):
            A list of table records.

        delimiter (str):
            The character to use for delimiting the values.
    """
    from tkinter.filedialog import asksaveasfilename
    import csv

    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    initialfile = f"tabledata_{timestamp}.csv"
    filetypes = [
        ("CSV UTF-8 (Comma delimited)", "*.csv"),
        ("All file types", "*.*"),
    ]
    filename = asksaveasfilename(
        confirmoverwrite=True,
        filetypes=filetypes,
        defaultextension="csv",
        initialfile=initialfile,
    )
    if filename:
        with open(filename, "w", encoding="utf-8", newline="") as f:
            writer = csv.writer(f, delimiter=delimiter)
            writer.writerow(headers)
            writer.writerows(records)

sort_column_data(event=None, cid=None, sort=None)

Sort the table rows by the specified column. This method may be trigged by an event or manually.

Parameters:

event (Event):
    A window event.

cid (int):
    A unique column identifier; typically the numerical
    index of the column relative to the original data set.

sort (int):
    Determines the sort direction. 0 = ASCENDING. 1 = DESCENDING.
Source code in src/ttkbootstrap/tableview.py
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
def sort_column_data(self, event=None, cid=None, sort=None):
    """Sort the table rows by the specified column. This method
    may be trigged by an event or manually.

    Parameters:

        event (Event):
            A window event.

        cid (int):
            A unique column identifier; typically the numerical
            index of the column relative to the original data set.

        sort (int):
            Determines the sort direction. 0 = ASCENDING. 1 = DESCENDING.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        column = eo.column
        index = column.tableindex
    elif cid is not None:
        column: TableColumn = self.cidmap.get(int(cid))
        index = column.tableindex
    else:
        return

    # update table data
    if self.is_filtered:
        tablerows = self.tablerows_filtered
    else:
        tablerows = self.tablerows

    if sort is not None:
        columnsort = sort
    else:
        columnsort = self.tablecolumns[index].columnsort

    if columnsort == ASCENDING:
        self._tablecols[index].columnsort = DESCENDING
    else:
        self._tablecols[index].columnsort = ASCENDING

    try:
        sortedrows = sorted(
            tablerows, reverse=columnsort, key=lambda x: x.values[index]
        )
    except:
        # when data is missing, or sometimes with numbers
        # this is still not right, but it works most of the time
        # fix sometime down the road when I have time
        self.fill_empty_columns()
        sortedrows = sorted(
            tablerows, reverse=columnsort, key=lambda x: int(x.values[index])
        )
    if self.is_filtered:
        self._tablerows_filtered = sortedrows
    else:
        self._tablerows = sortedrows

    # update headers
    self._column_sort_header_reset()
    self._column_sort_header_update(column.cid)

    self.unload_table_data()
    self.load_table_data()
    self._select_first_visible_item()

unhide_selected_column(event=None, cid=None)

Attach the selected column to the tableview. This method may be triggered by a window event or by specifying the column id. The column is reinserted at the index in the original data set.

Parameters:

event (Event):
    An application click event

cid (int):
    A unique column identifier; typically the numerical
    index of the column within the original dataset.
Source code in src/ttkbootstrap/tableview.py
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
def unhide_selected_column(self, event=None, cid=None):
    """Attach the selected column to the tableview. This method
    may be triggered by a window event or by specifying the column
    id. The column is reinserted at the index in the original data
    set.

    Parameters:

        event (Event):
            An application click event

        cid (int):
            A unique column identifier; typically the numerical
            index of the column within the original dataset.
    """
    if event is not None:
        eo = self._get_event_objects(event)
        eo.column.show()
    elif cid is not None:
        column = self.cidmap.get(cid)
        column.show()

unload_table_data()

Unload all data from the table

Source code in src/ttkbootstrap/tableview.py
1026
1027
1028
1029
1030
def unload_table_data(self):
    """Unload all data from the table"""
    for row in self.tablerows_visible:
        row.hide()
    self.tablerows_visible.clear()