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.

101 lines
3.0 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.ns('Ext.ux.grid');
  16. /**
  17. * @class Ext.ux.grid.TableGrid
  18. * @extends Ext.grid.GridPanel
  19. * A Grid which creates itself from an existing HTML table element.
  20. * @history
  21. * 2007-03-01 Original version by Nige "Animal" White
  22. * 2007-03-10 jvs Slightly refactored to reuse existing classes * @constructor
  23. * @param {String/HTMLElement/Ext.Element} table The table element from which this grid will be created -
  24. * The table MUST have some type of size defined for the grid to fill. The container will be
  25. * automatically set to position relative if it isn't already.
  26. * @param {Object} config A config object that sets properties on this grid and has two additional (optional)
  27. * properties: fields and columns which allow for customizing data fields and columns for this grid.
  28. */
  29. Ext.ux.grid.TableGrid = function(table, config){
  30. config = config ||
  31. {};
  32. Ext.apply(this, config);
  33. var cf = config.fields || [], ch = config.columns || [];
  34. table = Ext.get(table);
  35. var ct = table.insertSibling();
  36. var fields = [], cols = [];
  37. var headers = table.query("thead th");
  38. for (var i = 0, h; h = headers[i]; i++) {
  39. var text = h.innerHTML;
  40. var name = 'tcol-' + i;
  41. fields.push(Ext.applyIf(cf[i] ||
  42. {}, {
  43. name: name,
  44. mapping: 'td:nth(' + (i + 1) + ')/@innerHTML'
  45. }));
  46. cols.push(Ext.applyIf(ch[i] ||
  47. {}, {
  48. 'header': text,
  49. 'dataIndex': name,
  50. 'width': h.offsetWidth,
  51. 'tooltip': h.title,
  52. 'sortable': true
  53. }));
  54. }
  55. var ds = new Ext.data.Store({
  56. reader: new Ext.data.XmlReader({
  57. record: 'tbody tr'
  58. }, fields)
  59. });
  60. ds.loadData(table.dom);
  61. var cm = new Ext.grid.ColumnModel(cols);
  62. if (config.width || config.height) {
  63. ct.setSize(config.width || 'auto', config.height || 'auto');
  64. }
  65. else {
  66. ct.setWidth(table.getWidth());
  67. }
  68. if (config.remove !== false) {
  69. table.remove();
  70. }
  71. Ext.applyIf(this, {
  72. 'ds': ds,
  73. 'cm': cm,
  74. 'sm': new Ext.grid.RowSelectionModel(),
  75. autoHeight: true,
  76. autoWidth: false
  77. });
  78. Ext.ux.grid.TableGrid.superclass.constructor.call(this, ct, {});
  79. };
  80. Ext.extend(Ext.ux.grid.TableGrid, Ext.grid.GridPanel);
  81. //backwards compat
  82. Ext.grid.TableGrid = Ext.ux.grid.TableGrid;