jQuery Performant数据网格插件 巨大 网格

  • 源码大小:64.42KB
  • 所需积分:1积分
  • 源码编号:19JP-3411
  • 浏览次数:1054次
  • 最后更新:2023年06月10日
  • 所属栏目:表格
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

轻松处理数千条记录并显示它们。

大型数据集很难处理,尤其是在需要在单个页面上有大量记录的情况下

巨大网格是一个简单的jQuery插件,用于从大量数据中生成一个完全响应、高性能、功能丰富且高度可定制的数据表/网格

它的构建考虑到了性能,同时支持静态和动态数据、排序、滚动和过滤。您可以设置要预加载的视图区域之外的记录数,以提供更好的用户体验。

如何使用它:

1.在文档中加载最新的jQuery库和巨大网格插件的文件。

  1. <!-- Required Stylesheet For The Data Grid -->
  2. <link rel="stylesheet" href="/path/to/css/huge-grid.min.css" />
  3.  
  4. <!-- jQuery Library -->
  5. <script src="/path/to/cdn/jquery.slim.min.js"></script>
  6.  
  7. <!-- Main JavaScript -->
  8. <script src="/path/to/js/huge-grid.js"></script>

2.创建一个空的DIV容器来容纳数据网格。

  1. <div id="grid" style="height: 500px;">
  2. </div>

3.按如下方式准备表格数据。

  1. var myHeader = [
  2. {
  3. id: "id",
  4. content: "ID",
  5. width: 50
  6. },
  7. {
  8. id: "name",
  9. content: "Name",
  10. width: 200
  11. },
  12. // ...
  13. ];
  14.  
  15. var myData = [
  16. {
  17. id: "id",
  18. content: {
  19. id: "id",
  20. name: "name"
  21. }
  22. }
  23. // ...
  24. ];

4.初始化插件以生成可排序和可滚动的数据网格。

  1. $("#grid").hugeGrid({
  2. sortKey: "name",
  3. header: generateColumns(),
  4. data: generateData()
  5. });

5.可用于自定义数据网格的插件选项。

  1. $("#grid").hugeGrid({
  2.  
  3. // unique ID
  4. id: null,
  5.  
  6. // border width between headings and data
  7. splitterWidth: 2,
  8.  
  9. // number of columns to be fixed
  10. fixedColumns: 0,
  11.  
  12. // height of the header
  13. headRowHeight: 17,
  14.  
  15. // height of the filter row
  16. filterRowHeight: 26,
  17.  
  18. markedColumnBackground: '#DDD',
  19. // column id to sort data by
  20. sortKey: null,
  21.  
  22. // asc or desc
  23. sortDesc: false,
  24.  
  25. // when TRUE the sort row is not rendered.
  26. noSort: false,
  27.  
  28. // when TRUE grid automatically reorders rows when they change.
  29. autoSort: true,
  30.  
  31. // height of the sort row
  32. sortRowHeight: 20,
  33.  
  34. // custom sort markup
  35. sortMarkup: '<div class="hg-sort-inner"><div class="hg-sort-desc"></div><div class="hg-sort-asc"></div></div>',
  36. noSortMarkup: '',
  37.  
  38. // used only with ajax loading
  39. dataType: "json",
  40.  
  41. // data parameters
  42. dataParam: null,
  43.  
  44. // enable data filter
  45. filter: null,
  46.  
  47. // height of row
  48. rowHeight: 16,
  49.  
  50. // number of rows in one block
  51. blockSize: 8,
  52.  
  53. // number of root level columns / column groups in one horizontal block
  54. hBlockSize: 16,
  55.  
  56. // number of blocks/superblocks in one higher level superblock
  57. superblockSize: 16,
  58.  
  59. // number of levels of blocks / superblocks should be used
  60. blockLevels: 4,
  61.  
  62. // number of blocks are allowed to get loaded at the same time via ajax. value greater than 3 is not recommended.
  63. maxConcurrentLoads: 3,
  64.  
  65. // number of rows that are outside the view area should be preloaded
  66. preloadRows: 10,
  67.  
  68. // // the markup added to the block that is not yet loaded via ajax (left part)
  69. loadingBlockHeadMarkup: '<div class="hg-block-loading" />',
  70.  
  71. // the markup added to the block that is not yet loaded via ajax (right part)
  72. loadingBlockContMarkup: '<div class="hg-block-loading" />',
  73.  
  74. rangeBorderWidth: 1,
  75.  
  76. // 'none' (no selection),
  77. // 'single' (only columns on a single row),
  78. // 'multiple' (multiple columns and rows).
  79. selectionMode: 'none',
  80.  
  81. // what is the left most allowed selected column id
  82. selectionMinColumnId: null,
  83.  
  84. // what is the right most allowed selected column id
  85. selectionMaxColumnId: null,
  86.  
  87. // custom table footer
  88. footer: null,
  89. footerHeight: 19,
  90.  
  91. // scolling options
  92. hScrollPos: 0,
  93. vScrollPos: 0,
  94. hScrollHeight: 32,
  95. vScrollWidth: 32,
  96. hScrollSpeed: 360,
  97. vScrollSpeed: 120,
  98. hScrollMarkup: '<div class="hg-hscroll-tumb" />',
  99. vScrollMarkup: '<div class="hg-vscroll-tumb" />',
  100.  
  101. // touch options
  102. touchScrollSensitivity: 5,
  103. touchContextMenuTime: 1,
  104. dblTapTime: 0.5,
  105.  
  106. });

6.回调和函数。

  1. $("#grid").hugeGrid({
  2.  
  3. // function(rowData)
  4. rowTransformer: null,
  5.  
  6. // function(colId, isDesc) // return true if want to cancel sort switching
  7. onSort: function(colId, isDesc) { return this.onDefaultSort(colId, isDesc); },
  8.  
  9. // function(target)
  10. onMarkChange: null,
  11.  
  12. // function(target) Grid will not be reloaded if function returns FALSE.
  13. onFilterChange: null,
  14.  
  15. // function(event, delta, deltaX, deltaY) Must return TRUE to allow default grid scrolling.
  16. onBeforeWheelScroll: null,
  17.  
  18. // function(target)
  19. onMouseDown: null,
  20.  
  21. // function(target)
  22. onMouseUp: null,
  23.  
  24. // function(target)
  25. onSelectionStart: null,
  26.  
  27. // function(target)
  28. onSelectionChange: null,
  29.  
  30. // function(target)
  31. onSelectionEnd: null,
  32.  
  33. // function(target)
  34. onClick: null,
  35.  
  36. // function(target)
  37. onDblClick: null,
  38.  
  39. // function(event, target) Must return FALSE if default grid behaviour should be prevented.
  40. onTouchStart: null,
  41.  
  42. // function(event, target) Must return FALSE if default grid behaviour should be prevented.
  43. onTouchMove: null,
  44.  
  45. // function(event, target) Must return FALSE if default grid behaviour should be prevented.
  46. onTouchEnd: null,
  47.  
  48. // function(event, target)
  49. onTap: null,
  50.  
  51. // function(event, target)
  52. onDblTap: null,
  53.  
  54. // function(event, target) Must return FALSE to prevent further context menu events.
  55. onTouchContextMenuStart: null,
  56.  
  57. // function()
  58. onTouchContextMenuCancel: null,
  59.  
  60. // function(event, target) Must return TRUE to prevent further grid scrolling and tap callbacks if context menu was shown or any action taken.
  61. onTouchContextMenu: null,
  62.  
  63. // function(target)
  64. onOver: null,
  65.  
  66. // function(target)
  67. onOut: null,
  68.  
  69. // function(selection)
  70. onSelect: null,
  71.  
  72. // function(selection)
  73. onDeselect: null,
  74.  
  75. // function(rowIdxFrom, rowIdxTo)
  76. onLoad: null,
  77.  
  78. // function(rowIdxFrom, rowIdxTo)
  79. onUnload: null,
  80.  
  81. // function(hScrollPos, vScrollPos)
  82. onScroll: null,
  83.  
  84. // function(resp)
  85. onError: null,
  86.  
  87. // function(firstRowIdx, $leftBlockDomElement, $rightBlockDomElement)
  88. onBlockHide: null,
  89.  
  90. // function(filteredRows, unfilteredRows)
  91. onRowCountUpdate: null,
  92.  
  93. // function(requestData)
  94. onBeforeRequestData: null,
  95.  
  96. // function(response)
  97. onRowDataReceived: null,
  98.  
  99. // function(rowCount, firstVisibleRowIdx, lastVisibleRowIdx, previousFirstVisibleRowIdx, previousLastVisibleRowIdx)
  100. onViewUpdate: null,
  101.  
  102. // each key is column id and value is callback function(colId, isDesc, rowA, rowB)
  103. sortFunctions: {
  104. 'string': function(colId, isDesc, a, b) {
  105. var v1 = HugeGrid.getSortValue(a, colId, '');
  106. var v2 = HugeGrid.getSortValue(b, colId, '');
  107. if(v1 === v2)
  108. return 0;
  109. return ((v1 < v2) ? -1 : 1) * (isDesc ? -1 : 1);
  110. },
  111. 'numeric': function(colId, isDesc, a, b) {
  112. var v1 = HugeGrid.getSortValue(a, colId, 0);
  113. var v2 = HugeGrid.getSortValue(b, colId, 0);
  114.  
  115. if( typeof(v1) !== 'number') {
  116. v1 = parseFloat(v1.replace(/[^0-9.\-]+/g, ''));
  117. if( isNaN(v1) ) v1 = 0;
  118. }
  119.  
  120. if( typeof(v2) !== 'number') {
  121. v2 = parseFloat(v2.replace(/[^0-9.\-]+/g, ''));
  122. if( isNaN(v2) ) v2 = 0;
  123. }
  124.  
  125. if(v1 === v2)
  126. return 0;
  127. return ((v1 < v2) ? -1 : 1) * (isDesc ? -1 : 1);
  128. }
  129. }
  130.  
  131. });

预览截图