kendo-table-list-tree-object.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * 初始化 kendo ui Table list tree 的封装
  3. * @author LiaoYun 2019-09-17 945505778@qq.com
  4. */
  5. (function () {
  6. var KDListTreeTable = function (kdtableId, url, columns) {
  7. this.kdtableId = kdtableId;
  8. this.url = Feng.ctxPath + url;
  9. this.method = "post";
  10. this.columns = columns;
  11. this.height = 595; //默认表格高度665
  12. this.fields = {}; //data type of the field {number|string|boolean|date} default is string
  13. this.code = '';
  14. this.parentCode = '';
  15. this.resizable = true; //表格宽度允许拖动
  16. this.reorderable = true; //是否允许拖动列来改变列的显示顺序
  17. this.selectable = true; //是否允许选择
  18. if (columns!=null && columns.length>0) {
  19. for(var i=0; i<columns.length; i++){
  20. var temp = columns[i];
  21. if (!temp) {
  22. break;
  23. }
  24. if (temp.type!=null && temp.type!='' && typeof(temp)!="undefined") {
  25. this.fields[temp.field] = {'type': temp.type};
  26. } else {
  27. this.fields[temp.field] = {'type': 'string'};
  28. }
  29. }
  30. }
  31. };
  32. KDListTreeTable.prototype = {
  33. /**
  34. * 初始化kendo list tree table
  35. */
  36. init: function(){
  37. var tableId = this.kdtableId;
  38. var me = this;
  39. this.btInstance = $("#" + tableId).kendoTreeList({
  40. columns: this.columns,
  41. dataSource: {
  42. transport: {
  43. read: {
  44. url: this.url,
  45. type: this.method,
  46. dataType: "json",
  47. contentType: "application/x-www-form-urlencoded"
  48. },
  49. parameterMap: function(options, operation){
  50. console.log(options);
  51. if (operation == "read") {
  52. var parameter = {};
  53. $.each(options, function(name, value){
  54. parameter[name] = value;
  55. });
  56. return parameter;
  57. }
  58. }
  59. },
  60. schema: {
  61. model: {
  62. id: this.code,
  63. parentId: this.parentCode,
  64. fields: this.fields
  65. }
  66. }
  67. },
  68. resizable: this.resizable,
  69. height: this.height,
  70. reorderable: this.reorderable,
  71. selectable: this.selectable,
  72. refresh: true
  73. });
  74. return this;
  75. },
  76. setTreeCode: function(code, parentCode) {
  77. this.code = code;
  78. this.parentCode = parentCode;
  79. },
  80. getSelections: function() {
  81. var grid = $("#"+this.kdtableId+",.k-grid-content").data("kendoTreeList");
  82. var selected = [];
  83. var rows = grid.select();
  84. // console.log(rows);
  85. for(var i=0; i<rows.length; i++){
  86. var temp = rows.eq(i);
  87. var className = temp.parent().parent().parent().attr("class");
  88. // console.log("class=" + temp.parent().parent().parent().attr("class"));
  89. if (className === 'k-grid-content-locked') {
  90. continue;
  91. }
  92. selected.push(grid.dataItem(rows[i]))
  93. }
  94. console.log(selected);
  95. return selected;
  96. },
  97. refresh: function(val) {
  98. var grid = $("#"+this.kdtableId).data("kendoTreeList");
  99. if (val && val.query) {
  100. var filter = [];
  101. var flag = false;
  102. $.each(val.query, function(name, value){
  103. if (value!=null && value!='' && typeof(value)!="undefined") {
  104. flag = true;
  105. } else {
  106. delete val.query[name];
  107. }
  108. });
  109. if (flag) {
  110. val.query.page = 1;
  111. val.query.pageSize = this.pageSize;
  112. val.query.take = this.pageSize;
  113. val.query.skip = 0;
  114. grid.dataSource.query(val.query);
  115. } else {
  116. grid.dataSource.read();
  117. }
  118. } else {
  119. grid.dataSource.read();
  120. }
  121. }
  122. };
  123. window.KDListTreeTable = KDListTreeTable;
  124. }());