diff --git a/.changeset/easy-geese-live.md b/.changeset/easy-geese-live.md new file mode 100644 index 0000000000000..bcf6712dbffe4 --- /dev/null +++ b/.changeset/easy-geese-live.md @@ -0,0 +1,7 @@ +--- +"@gradio/dataframe": minor +"@gradio/utils": minor +"gradio": minor +--- + +feat:Allow accessing the entire row of selected values in `gr.DataFrame` diff --git a/.gitignore b/.gitignore index 5cd4e06dcb53b..b69ad66caf7d2 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ gradio/launches.json flagged/ gradio_cached_examples/ tmp.zip +gradio/hash_seed.txt # Tests .coverage diff --git a/gradio/events.py b/gradio/events.py index 6411b303384c5..638ab48f349c1 100644 --- a/gradio/events.py +++ b/gradio/events.py @@ -194,6 +194,14 @@ def __init__(self, target: Block | None, data: Any): """ The value of the selected item. """ + self.row_value: Any = data.get("row_value") + """ + The value of the entire row that the selected item belongs to, as a 1-D list. Only implemented for the `Dataframe` component, returns None for other components. + """ + self.col_value: Any = data.get("col_value") + """ + The value of the entire row that the selected item belongs to, as a 1-D list. Only implemented for the `Dataframe` component, returns None for other components. + """ self.selected: bool = data.get("selected", True) """ True if the item was selected, False if deselected. diff --git a/js/dataframe/shared/Table.svelte b/js/dataframe/shared/Table.svelte index 368f4fcd0297a..fc21c83c41b4c 100644 --- a/js/dataframe/shared/Table.svelte +++ b/js/dataframe/shared/Table.svelte @@ -65,7 +65,11 @@ if (selected !== false) { const [row, col] = selected; if (!isNaN(row) && !isNaN(col)) { - dispatch("select", { index: [row, col], value: get_data_at(row, col) }); + dispatch("select", { + index: [row, col], + value: get_data_at(row, col), + row_value: data[row].map((d) => d.value) + }); } } } diff --git a/js/utils/src/utils.ts b/js/utils/src/utils.ts index 917dac2b56bcc..6c838b64372e4 100644 --- a/js/utils/src/utils.ts +++ b/js/utils/src/utils.ts @@ -2,6 +2,7 @@ import type { ActionReturn } from "svelte/action"; import type { Client } from "@gradio/client"; export interface SelectData { + row_value?: any[]; index: number | [number, number]; value: any; selected?: boolean;