|
96 | 96 | You can set additional `tags` like a [caption](https://datatables.net/blog/2014-11-07) on the table with the `tags` option: |
97 | 97 |
|
98 | 98 | ```{code-cell} |
99 | | -show(df, tags='<caption>Countries from the World Bank Database</caption>') |
| 99 | +show(df, tags="<caption>Countries from the World Bank Database</caption>") |
100 | 100 | ``` |
101 | 101 |
|
102 | 102 | The position of the caption can be set explicitly as in the datatables example above (note that the default position may depend on how you render the notebook): |
| 103 | + |
| 104 | +```{code-cell} |
| 105 | +show( |
| 106 | + df, |
| 107 | + tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>', |
| 108 | +) |
| 109 | +``` |
| 110 | + |
| 111 | +```{code-cell} |
| 112 | +opt.lengthMenu = [5, 10, 20, 50, 100, 200, 500] |
| 113 | +``` |
| 114 | + |
| 115 | +## Table footer |
| 116 | + |
| 117 | +Use `footer = True` if you wish to display a table footer. |
| 118 | + |
| 119 | +```{code-cell} |
| 120 | +show(df, footer=True) |
| 121 | +``` |
| 122 | + |
| 123 | +## Column filters |
| 124 | + |
| 125 | +Use `column_filters = "header"` or `"footer"` if you wish to display individual column filters |
| 126 | +(remove the global search box with [`dom='lrtip'`](https://datatables.net/reference/option/dom) if desired). |
| 127 | + |
103 | 128 | ```{code-cell} |
104 | | -show(df, tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>') |
| 129 | +alpha_numeric_df = pd.DataFrame( |
| 130 | + [["one", 1.5], ["two", 2.3]], columns=["string", "numeric"] |
| 131 | +) |
| 132 | +
|
| 133 | +show(alpha_numeric_df, column_filters="footer", dom="lrtip") |
| 134 | +``` |
| 135 | + |
| 136 | +As always you can set activate column filters by default with e.g. |
| 137 | + |
| 138 | +```{code-cell} |
| 139 | +opt.column_filters = "footer" |
| 140 | +alpha_numeric_df |
| 141 | +``` |
| 142 | + |
| 143 | +Column filters also work on dataframes with multiindex columns: |
| 144 | + |
| 145 | +```{code-cell} |
| 146 | +from itables.sample_dfs import get_dict_of_test_dfs |
| 147 | +
|
| 148 | +get_dict_of_test_dfs()["multiindex"] |
| 149 | +``` |
| 150 | + |
| 151 | +Now we deactivate the column filters for the rest of the notebook |
| 152 | + |
| 153 | +```{code-cell} |
| 154 | +opt.column_filters = False |
105 | 155 | ``` |
106 | 156 |
|
107 | 157 | ## Float precision |
@@ -129,22 +179,27 @@ You can use Javascript callbacks to set the cell or row style depending on the c |
129 | 179 |
|
130 | 180 | The example below, in which we color in red the cells with negative numbers, is directly inspired by the corresponding datatables.net [example](https://datatables.net/reference/option/columns.createdCell). |
131 | 181 |
|
| 182 | +Note how the Javascript callback is declared as `JavascriptFunction` object below. |
| 183 | + |
132 | 184 | ```{code-cell} |
| 185 | +from itables import JavascriptFunction |
| 186 | +
|
133 | 187 | show( |
134 | 188 | pd.DataFrame([[-1, 2, -3, 4, -5], [6, -7, 8, -9, 10]], columns=list("abcde")), |
135 | 189 | columnDefs=[ |
136 | 190 | { |
137 | 191 | "targets": "_all", |
138 | | - "createdCell": """ |
| 192 | + "createdCell": JavascriptFunction( |
| 193 | + """ |
139 | 194 | function (td, cellData, rowData, row, col) { |
140 | 195 | if (cellData < 0) { |
141 | 196 | $(td).css('color', 'red') |
142 | 197 | } |
143 | 198 | } |
144 | | -""", |
| 199 | +""" |
| 200 | + ), |
145 | 201 | } |
146 | 202 | ], |
147 | | - eval_functions=True, |
148 | 203 | ) |
149 | 204 | ``` |
150 | 205 |
|
@@ -214,7 +269,7 @@ show( |
214 | 269 | The [search option](https://datatables.net/reference/option/search) let you control the initial value for the search field, and whether the query should be treated as a regular expression or not: |
215 | 270 |
|
216 | 271 | ```{code-cell} |
217 | | -show(df, search={"regex": True, "caseInsensitive": True, "search":"s.ain"}) |
| 272 | +show(df, search={"regex": True, "caseInsensitive": True, "search": "s.ain"}) |
218 | 273 | ``` |
219 | 274 |
|
220 | 275 | ## Select rows |
|
0 commit comments