T_TableView.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import QtQuick.Window
  5. import FluentUI
  6. import "../component"
  7. FluScrollablePage{
  8. title:"TableView"
  9. leftPadding:10
  10. rightPadding:10
  11. bottomPadding:20
  12. spacing: 0
  13. Component.onCompleted: {
  14. const columns = [
  15. {
  16. title: '姓名',
  17. dataIndex: 'name',
  18. width:100
  19. },
  20. {
  21. title: '年龄',
  22. dataIndex: 'age',
  23. width:100
  24. },
  25. {
  26. title: '住址',
  27. dataIndex: 'address',
  28. width:200
  29. },
  30. {
  31. title: '别名',
  32. dataIndex: 'nickname',
  33. width:100
  34. },
  35. {
  36. title: '操作',
  37. dataIndex: 'action',
  38. width:100
  39. },
  40. ];
  41. table_view.columns = columns
  42. loadData(1,10)
  43. }
  44. FluTableView{
  45. id:table_view
  46. Layout.fillWidth: true
  47. Layout.topMargin: 20
  48. pageCurrent:1
  49. pageCount:10
  50. itemCount: 1000
  51. onRequestPage:
  52. (page,count)=> {
  53. loadData(page,count)
  54. }
  55. }
  56. Component{
  57. id:com_action
  58. Item{
  59. Row{
  60. anchors.centerIn: parent
  61. spacing: 10
  62. FluFilledButton{
  63. text:"编辑"
  64. topPadding:3
  65. bottomPadding:3
  66. leftPadding:6
  67. rightPadding:6
  68. onClicked:{
  69. showSuccess(JSON.stringify(dataObject))
  70. }
  71. }
  72. FluFilledButton{
  73. text:"删除"
  74. topPadding:3
  75. bottomPadding:3
  76. leftPadding:6
  77. rightPadding:6
  78. onClicked:{
  79. showError(JSON.stringify(dataObject))
  80. }
  81. }
  82. }
  83. }
  84. }
  85. function loadData(page,count){
  86. const dataSource = []
  87. for(var i=0;i<count;i++){
  88. dataSource.push({
  89. name: "孙悟空%1".arg(((page-1)*count+i)),
  90. age: 500,
  91. address: "钟灵毓秀的花果山,如神仙仙境的水帘洞",
  92. nickname: "齐天大圣",
  93. action:com_action
  94. })
  95. }
  96. table_view.dataSource = dataSource
  97. }
  98. CodeExpander{
  99. Layout.fillWidth: true
  100. Layout.topMargin: 10
  101. code:'FluTableView{
  102. id:table_view
  103. Layout.fillWidth: true
  104. Layout.topMargin: 20
  105. pageCurrent:1
  106. pageCount:10
  107. itemCount: 1000
  108. onRequestPage:
  109. (page,count)=> {
  110. loadData(page,count)
  111. }
  112. Component.onCompleted: {
  113. const columns = [
  114. {
  115. title: "姓名",
  116. dataIndex: "name",
  117. width:100
  118. },
  119. {
  120. title: "年龄",
  121. dataIndex: "age",
  122. width:100
  123. },
  124. {
  125. title: "住址",
  126. dataIndex: "address",
  127. width:200
  128. },
  129. {
  130. title: "别名",
  131. dataIndex: "nickname",
  132. width:100
  133. }
  134. ];
  135. table_view.columns = columns
  136. const dataSource = [
  137. {
  138. name: "孙悟空”,
  139. age: 500,
  140. address:"钟灵毓秀的花果山,如神仙仙境的水帘洞",
  141. nickname:"齐天大圣"
  142. }
  143. ];
  144. table_view.dataSource = columns
  145. }
  146. }'
  147. }
  148. }