You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.4 KiB
106 lines
2.4 KiB
import uuid
|
|
import dash
|
|
from dash import html
|
|
import feffery_antd_components as fac
|
|
from dash.dependencies import Input, Output, State
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.callback(
|
|
Output('test_table_demo', 'data'),
|
|
Input('test_table_demo', 'buttonClick'),
|
|
State('test_table_demo', 'data'),
|
|
State('test_table_demo', 'selectedRowKeys'),
|
|
State('test_table_demo', 'clickedContent'),
|
|
State('test_table_demo', 'recentlyButtonClickedRow'),
|
|
prevent_initial_call=True
|
|
)
|
|
def test_table_demo(button_click, data, selected_row_keys, clicked_content, recently_button_clicked_row):
|
|
if button_click == '修改':
|
|
return [
|
|
{
|
|
'model_uid': 'test2-instruct',
|
|
'model_name': 'test2-instruct'
|
|
}
|
|
]
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 准备数据,并为每一行添加唯一的 key 和 actions 列
|
|
mode_llm_run_data = [{
|
|
'model_uid': 'test2-instruct',
|
|
'model_name': 'test2-instruct'
|
|
}]
|
|
|
|
for item in mode_llm_run_data:
|
|
item['key'] = str(uuid.uuid4()) # 添加唯一的 key
|
|
item['actions'] = [
|
|
{
|
|
'content': '修改',
|
|
'type': 'link',
|
|
'icon': 'antd-edit'
|
|
},
|
|
{
|
|
'content': '删除',
|
|
'type': 'link',
|
|
'icon': 'antd-delete'
|
|
},
|
|
]
|
|
|
|
# 定义表格的列,包括 actions 列的 renderOptions
|
|
columns = [
|
|
{
|
|
'dataIndex': 'model_uid',
|
|
'title': 'model_uid',
|
|
'width': '10%'
|
|
},
|
|
{
|
|
'dataIndex': 'model_name',
|
|
'title': 'model_name',
|
|
'width': '10%'
|
|
},
|
|
{
|
|
'dataIndex': 'actions',
|
|
'title': 'actions',
|
|
'width': '15%',
|
|
'renderOptions': {
|
|
'renderType': 'button'
|
|
}
|
|
},
|
|
]
|
|
|
|
app.layout = html.Div(
|
|
[
|
|
fac.AntdTable(
|
|
id='test_table_demo',
|
|
columns=columns,
|
|
data=mode_llm_run_data,
|
|
pagination=False, # 禁用分页
|
|
style={
|
|
'cursor': 'pointer',
|
|
'width': "100%",
|
|
'flex': '1 1 auto', # 分配 flex 比例
|
|
'fontSize': '0.8rem', # 减小字体以降低表格行高
|
|
},
|
|
),
|
|
],
|
|
style={
|
|
'padding': 100
|
|
}
|
|
)
|
|
|
|
# (可选)定义回调以处理按钮点击事件
|
|
# 您可以根据需要添加回调,以处理 "修改" 和 "删除" 按钮的点击事件。
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|