Skip to content

Commit 4f0457c

Browse files
committed
docs: data changes example for Pagination
1 parent 0e7d465 commit 4f0457c

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

docs/components/antd/pagination/README-zh_CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ A long list can be divided into several pages, and only one page will be loaded
55
## Examples
66

77
<demo name="basic"></demo>
8+
9+
### Data Changes
10+
11+
The `Pagination` component is not designed as a data component and cannot be placed in the inputs of other events, but you can get the changed value of the pagination through the pagination change event. If you need to persist the page data, you can save it to `gr.State`
12+
13+
<demo name="data_changes">

docs/components/antd/pagination/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ A long list can be divided into several pages, and only one page will be loaded
55
## Examples
66

77
<demo name="basic"></demo>
8+
9+
### Data Changes
10+
11+
The `Pagination` component is not designed as a data component and cannot be placed in the inputs of other events, but you can get the changed value of the pagination through the pagination change event. If you need to persist the page data, you can save it to `gr.State`
12+
13+
<demo name="data_changes">
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import gradio as gr
2+
import modelscope_studio.components.antd as antd
3+
import modelscope_studio.components.base as ms
4+
5+
6+
def on_change(e: gr.EventData, state_value):
7+
page = e._data["payload"][0]
8+
page_size = e._data["payload"][1]
9+
state_value["page"] = page
10+
state_value["page_size"] = page_size
11+
return state_value
12+
13+
14+
def on_click(state_value):
15+
gr.Info(
16+
f"Page: {state_value['page']}, Page Size: {state_value['page_size']}")
17+
18+
19+
with gr.Blocks() as demo:
20+
state = gr.State({"page": 1, "page_size": 10})
21+
with ms.Application():
22+
with antd.ConfigProvider():
23+
with antd.Flex(vertical=True, gap="middle"):
24+
pagination = antd.Pagination(
25+
total=85,
26+
show_quick_jumper=True,
27+
show_size_changer=True,
28+
)
29+
btn = antd.Button("Show me the page",
30+
type="primary",
31+
block=True)
32+
pagination.change(fn=on_change, inputs=[state], outputs=[state])
33+
btn.click(fn=on_click, inputs=[state], outputs=[btn])
34+
if __name__ == "__main__":
35+
demo.queue().launch()

0 commit comments

Comments
 (0)