FluTableView.qml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Layouts
  4. import FluentUI
  5. Item {
  6. property var columns : []
  7. property var dataSource : []
  8. property int pageCurrent: 1
  9. property int itemCount: 1000
  10. property int pageCount: 10
  11. property int itemHeight: 56
  12. signal requestPage(int page,int count)
  13. id:control
  14. implicitHeight: layout_table.height
  15. QtObject{
  16. id:d
  17. property int coumnsWidth: parent.width
  18. }
  19. MouseArea{
  20. anchors.fill: parent
  21. preventStealing: true
  22. }
  23. ListModel{
  24. id:model_coumns
  25. }
  26. ListModel{
  27. id:model_data_source
  28. }
  29. onColumnsChanged: {
  30. model_coumns.clear()
  31. model_coumns.append(columns)
  32. var w = 0
  33. for(var i=0;i<model_coumns.count;i++){
  34. var item = model_coumns.get(i)
  35. w=w+item.width
  36. }
  37. d.coumnsWidth = w
  38. }
  39. onDataSourceChanged: {
  40. model_data_source.clear()
  41. model_data_source.append(dataSource)
  42. }
  43. Flickable{
  44. id:layout_flickable
  45. height: layout_table.height
  46. anchors{
  47. top: parent.top
  48. left: parent.left
  49. right: parent.right
  50. }
  51. contentWidth: layout_table.width
  52. ScrollBar.horizontal: FluScrollBar {
  53. }
  54. Rectangle{
  55. anchors.fill: layout_table
  56. radius: 5
  57. color: FluTheme.dark ? Qt.rgba(39/255,39/255,39/255,1) : Qt.rgba(251/255,251/255,253/255,1)
  58. }
  59. ListView{
  60. id:layout_table
  61. height: contentHeight
  62. width: Math.max(layout_flickable.width,d.coumnsWidth)
  63. clip:true
  64. interactive: false
  65. header: FluRectangle{
  66. id:layout_coumns
  67. height: control.itemHeight
  68. width: parent.width
  69. color:FluTheme.dark ? Qt.rgba(50/255,50/255,50/255,1) : Qt.rgba(247/255,247/255,247/255,1)
  70. radius: [5,5,0,0]
  71. Row{
  72. id:list_coumns
  73. spacing: 0
  74. anchors.fill: parent
  75. Repeater{
  76. model: model_coumns
  77. delegate: Item{
  78. height: list_coumns.height
  79. width: model.width
  80. FluText{
  81. text:model.title
  82. wrapMode: Text.WordWrap
  83. anchors{
  84. verticalCenter: parent.verticalCenter
  85. left: parent.left
  86. leftMargin: 14
  87. }
  88. fontStyle: FluText.BodyStrong
  89. }
  90. FluDivider{
  91. width: 1
  92. height: 40
  93. anchors.right: parent.right
  94. anchors.verticalCenter: parent.verticalCenter
  95. visible: index !== list_coumns.count-1
  96. }
  97. }
  98. }
  99. }
  100. }
  101. footer: Item{
  102. height: 50
  103. width: layout_table.width
  104. FluPagination{
  105. id:pagination
  106. height: 40
  107. pageCurrent: control.pageCurrent
  108. itemCount: control.itemCount
  109. pageCount: control.pageCount
  110. onRequestPage:
  111. (page,count)=> {
  112. control.requestPage(page,count)
  113. }
  114. anchors{
  115. top: parent.top
  116. right: parent.right
  117. }
  118. }
  119. }
  120. model:model_data_source
  121. delegate: Item{
  122. height: table_row.maxHeight
  123. width: layout_table.width
  124. property var model_values : getObjectValues(index)
  125. property var itemObject: getObject(index)
  126. property var listModel: model
  127. Row{
  128. id: table_row
  129. spacing: 0
  130. anchors.fill: parent
  131. property int maxHeight: itemHeight
  132. Repeater{
  133. model: model_values
  134. delegate:Item{
  135. height: table_row.maxHeight
  136. width: modelData.width
  137. Loader{
  138. property var model : modelData
  139. property var dataModel : listModel
  140. property var dataObject : itemObject
  141. anchors.fill: parent
  142. sourceComponent: {
  143. if(model.itemData instanceof Component){
  144. return model.itemData
  145. }
  146. return com_text
  147. }
  148. onHeightChanged:
  149. {
  150. table_row.maxHeight = Math.max(table_row.maxHeight,height,itemHeight)
  151. parent.height = table_row.maxHeight
  152. table_row.parent.height = table_row.maxHeight
  153. }
  154. }
  155. }
  156. }
  157. }
  158. FluDivider{
  159. width: parent.width
  160. height: 1
  161. anchors.right: parent.right
  162. anchors.bottom: parent.bottom
  163. }
  164. }
  165. }
  166. }
  167. Component{
  168. id:com_text
  169. Item{
  170. MouseArea{
  171. id:item_mouse
  172. hoverEnabled: true
  173. anchors.fill: parent
  174. }
  175. FluText{
  176. id:table_value
  177. text:String(model.itemData)
  178. width: parent.width - 14
  179. wrapMode: Text.WordWrap
  180. onImplicitHeightChanged: parent.parent.parent.height = Math.max(implicitHeight + 20,itemHeight)
  181. anchors{
  182. verticalCenter: parent.verticalCenter
  183. left: parent.left
  184. leftMargin: 14
  185. }
  186. FluTooltip{
  187. visible: item_mouse.containsMouse
  188. text:parent.text
  189. delay: 1000
  190. }
  191. }
  192. }
  193. }
  194. function getObject(index){
  195. return model_data_source.get(index)
  196. }
  197. function getObjectValues(index) {
  198. var obj = model_data_source.get(index)
  199. if(!obj)
  200. return
  201. var data = []
  202. for(var i=0;i<model_coumns.count;i++){
  203. var item = model_coumns.get(i)
  204. data.push({itemData:obj[item.dataIndex],width:item.width})
  205. }
  206. return data;
  207. }
  208. }