|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "98f76270-7807-4371-bb3a-cfcd03eb08c4", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "### `ipydatagrid` supports auto-fitting of column widths!\n", |
| 9 | + "\n", |
| 10 | + "The DataGrid constructor can take the following arguments:\n", |
| 11 | + "1. `auto_fit_columns`: boolean, indicates whether to auot-fit column widths. Setting to False will reset all column sizes to `base_column_size`.\n", |
| 12 | + "2. `auto_fit_params` : dict, allows for more granular customisation of the auto-fitting algorithm:\n", |
| 13 | + " * `area`: select which section of the grid to apply auto-fitting on. Possible options are `all`, `row-header` (index column) and `body`.\n", |
| 14 | + " * `padding`: specifies how much padding should be added to the width of each column after resizing (default 30) \n", |
| 15 | + " * `numCols`: set a hard cap on the number of columns to resize for the selected area (optional). Not setting this value means there is no cap." |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + "cell_type": "code", |
| 20 | + "execution_count": 5, |
| 21 | + "id": "6eef27bd", |
| 22 | + "metadata": {}, |
| 23 | + "outputs": [ |
| 24 | + { |
| 25 | + "data": { |
| 26 | + "application/vnd.jupyter.widget-view+json": { |
| 27 | + "model_id": "0a72e7e0e6844989856658cc60b57310", |
| 28 | + "version_major": 2, |
| 29 | + "version_minor": 0 |
| 30 | + }, |
| 31 | + "text/plain": [ |
| 32 | + "DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, corner_renderer=None, default_render…" |
| 33 | + ] |
| 34 | + }, |
| 35 | + "metadata": {}, |
| 36 | + "output_type": "display_data" |
| 37 | + } |
| 38 | + ], |
| 39 | + "source": [ |
| 40 | + "import numpy as np\n", |
| 41 | + "import pandas as pd\n", |
| 42 | + "from ipydatagrid import DataGrid\n", |
| 43 | + "\n", |
| 44 | + "df = pd.DataFrame(data={\"Col1HasAVeryLongName\":[1,2,4], \"Col2MediumName\": [4,5,6], \"Col3\":[7,8,9]})\n", |
| 45 | + "grid = DataGrid(df, index_name=\"index_column\", layout={\"height\":\"90px\"})\n", |
| 46 | + "grid" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 2, |
| 52 | + "id": "d5560dea", |
| 53 | + "metadata": {}, |
| 54 | + "outputs": [], |
| 55 | + "source": [ |
| 56 | + "grid.auto_fit_columns = True" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": 6, |
| 62 | + "id": "e99d654e", |
| 63 | + "metadata": {}, |
| 64 | + "outputs": [], |
| 65 | + "source": [ |
| 66 | + "grid.auto_fit_columns = False" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": 9, |
| 72 | + "id": "add87d0d", |
| 73 | + "metadata": {}, |
| 74 | + "outputs": [], |
| 75 | + "source": [ |
| 76 | + "grid.auto_fit_params = {\n", |
| 77 | + " \"area\": \"body\",\n", |
| 78 | + " \"padding\": 60,\n", |
| 79 | + " \"numCols\": 1\n", |
| 80 | + "}\n", |
| 81 | + "grid.auto_fit_columns = True" |
| 82 | + ] |
| 83 | + } |
| 84 | + ], |
| 85 | + "metadata": { |
| 86 | + "kernelspec": { |
| 87 | + "display_name": "Python 3 (ipykernel)", |
| 88 | + "language": "python", |
| 89 | + "name": "python3" |
| 90 | + }, |
| 91 | + "language_info": { |
| 92 | + "codemirror_mode": { |
| 93 | + "name": "ipython", |
| 94 | + "version": 3 |
| 95 | + }, |
| 96 | + "file_extension": ".py", |
| 97 | + "mimetype": "text/x-python", |
| 98 | + "name": "python", |
| 99 | + "nbconvert_exporter": "python", |
| 100 | + "pygments_lexer": "ipython3", |
| 101 | + "version": "3.8.11" |
| 102 | + } |
| 103 | + }, |
| 104 | + "nbformat": 4, |
| 105 | + "nbformat_minor": 5 |
| 106 | +} |
0 commit comments