FluentUI/example/qml/page/T_TableView.qml

146 lines
4.2 KiB
QML
Raw Normal View History

2023-04-07 18:27:50 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import FluentUI
2023-04-22 16:02:52 +08:00
import "../component"
2023-04-07 18:27:50 +08:00
FluScrollablePage{
title:"TableView"
Component.onCompleted: {
const columns = [
{
title: '姓名',
dataIndex: 'name',
width:100
},
{
title: '年龄',
dataIndex: 'age',
width:100
},
{
title: '住址',
dataIndex: 'address',
width:200
},
{
title: '别名',
dataIndex: 'nickname',
width:100
},
{
title: '操作',
dataIndex: 'action',
2023-05-15 21:14:37 +08:00
width:120
2023-04-07 18:27:50 +08:00
},
];
table_view.columns = columns
loadData(1,10)
}
FluTableView{
id:table_view
Layout.fillWidth: true
Layout.topMargin: 20
pageCurrent:1
pageCount:10
itemCount: 1000
onRequestPage:
(page,count)=> {
loadData(page,count)
}
}
Component{
id:com_action
Item{
Row{
anchors.centerIn: parent
spacing: 10
FluFilledButton{
text:"编辑"
2023-05-15 21:14:37 +08:00
horizontalPadding: 6
2023-04-07 18:27:50 +08:00
onClicked:{
showSuccess(JSON.stringify(dataObject))
}
}
FluFilledButton{
text:"删除"
2023-05-15 21:14:37 +08:00
horizontalPadding: 6
2023-04-07 18:27:50 +08:00
onClicked:{
showError(JSON.stringify(dataObject))
}
}
}
}
}
2023-04-09 19:29:50 +08:00
2023-04-08 20:08:26 +08:00
CodeExpander{
Layout.fillWidth: true
Layout.topMargin: 10
code:'FluTableView{
id:table_view
Layout.fillWidth: true
Layout.topMargin: 20
pageCurrent:1
pageCount:10
itemCount: 1000
onRequestPage:
(page,count)=> {
loadData(page,count)
}
Component.onCompleted: {
const columns = [
{
title: "姓名",
dataIndex: "name",
width:100
},
{
title: "年龄",
dataIndex: "age",
width:100
},
{
title: "住址",
dataIndex: "address",
width:200
},
{
title: "别名",
dataIndex: "nickname",
width:100
}
];
2023-04-19 18:04:14 +08:00
table_view.columns = columns
2023-04-08 20:08:26 +08:00
const dataSource = [
2023-04-19 18:04:14 +08:00
{
name: ",
age: 500,
address:"钟灵毓秀的花果山,如神仙仙境的水帘洞",
2023-04-08 20:08:26 +08:00
nickname:"齐天大圣"
2023-04-19 18:04:14 +08:00
}
];
2023-04-08 20:08:26 +08:00
table_view.dataSource = columns
}
}'
}
2023-04-07 18:27:50 +08:00
2023-05-15 21:14:37 +08:00
function loadData(page,count){
const dataSource = []
for(var i=0;i<count;i++){
dataSource.push({
name: "孙悟空%1".arg(((page-1)*count+i)),
age: 500,
address: "钟灵毓秀的花果山,如神仙仙境的水帘洞",
nickname: "齐天大圣",
action:com_action
})
}
table_view.dataSource = dataSource
}
2023-04-07 18:27:50 +08:00
}