Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

accessor.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2. /* Tabulator v4.6.3 (c) Oliver Folkerd */
  3. var Accessor = function Accessor(table) {
  4. this.table = table; //hold Tabulator object
  5. this.allowedTypes = ["", "data", "download", "clipboard", "print", "htmlOutput"]; //list of accessor types
  6. };
  7. //initialize column accessor
  8. Accessor.prototype.initializeColumn = function (column) {
  9. var self = this,
  10. match = false,
  11. config = {};
  12. this.allowedTypes.forEach(function (type) {
  13. var key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1)),
  14. accessor;
  15. if (column.definition[key]) {
  16. accessor = self.lookupAccessor(column.definition[key]);
  17. if (accessor) {
  18. match = true;
  19. config[key] = {
  20. accessor: accessor,
  21. params: column.definition[key + "Params"] || {}
  22. };
  23. }
  24. }
  25. });
  26. if (match) {
  27. column.modules.accessor = config;
  28. }
  29. };
  30. Accessor.prototype.lookupAccessor = function (value) {
  31. var accessor = false;
  32. //set column accessor
  33. switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
  34. case "string":
  35. if (this.accessors[value]) {
  36. accessor = this.accessors[value];
  37. } else {
  38. console.warn("Accessor Error - No such accessor found, ignoring: ", value);
  39. }
  40. break;
  41. case "function":
  42. accessor = value;
  43. break;
  44. }
  45. return accessor;
  46. };
  47. //apply accessor to row
  48. Accessor.prototype.transformRow = function (dataIn, type) {
  49. var self = this,
  50. key = "accessor" + (type.charAt(0).toUpperCase() + type.slice(1));
  51. //clone data object with deep copy to isolate internal data from returned result
  52. var data = Tabulator.prototype.helpers.deepClone(dataIn || {});
  53. self.table.columnManager.traverse(function (column) {
  54. var value, accessor, params, component;
  55. if (column.modules.accessor) {
  56. accessor = column.modules.accessor[key] || column.modules.accessor.accessor || false;
  57. if (accessor) {
  58. value = column.getFieldValue(data);
  59. if (value != "undefined") {
  60. component = column.getComponent();
  61. params = typeof accessor.params === "function" ? accessor.params(value, data, type, component) : accessor.params;
  62. column.setFieldValue(data, accessor.accessor(value, data, type, params, component));
  63. }
  64. }
  65. }
  66. });
  67. return data;
  68. },
  69. //default accessors
  70. Accessor.prototype.accessors = {};
  71. Tabulator.prototype.registerModule("accessor", Accessor);