yvanui.yvgrid.filter.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**
  2. * yvan.yvgrid.filter.js
  3. * @author luoyifan
  4. * 2019-07-16 20:09:00
  5. */
  6. 'use strict';
  7. (function ($) {
  8. $.extend($.fn.yvgrid.methods, {
  9. clearfilters: function ($dom) {
  10. return $dom.jqxGrid('clearfilters');
  11. }
  12. });
  13. $.fn.yvgrid.filter = {
  14. sourceFilterOption: function ($dom, easyuiOpt, source, jqxOption) {
  15. if (source.datatype === 'array') {
  16. //本地过滤
  17. $.extend(jqxOption, {
  18. virtualmode: false,
  19. rendergridrows: null,
  20. });
  21. } else {
  22. //服务器过滤
  23. $.extend(source, {
  24. filter: function () {
  25. $dom.jqxGrid('updatebounddata', 'filter');
  26. },
  27. });
  28. }
  29. },
  30. columnFilterOption: function ($dom, easyuiOpt, easyuiColumnOpt, jqxColumnOpt) {
  31. if (!easyuiOpt.filter) {
  32. return;
  33. }
  34. if (easyuiColumnOpt.filter === false) {
  35. $.extend(jqxColumnOpt, {
  36. filterable: false
  37. });
  38. return;
  39. }
  40. switch (easyuiColumnOpt.type) {
  41. case 'number':
  42. $.extend(jqxColumnOpt, {
  43. filtertype: 'textbox',
  44. createfilterwidget: function (column, columnElement, widget) {
  45. //这里要修改 jqxgrid.filter.js 源码 1861 / 1867 / 2156
  46. //搜索 if(K.keyCode=="13"){I._applyfilterfromfilterrow()}if(f[0]._writeTimer){clearTimeout(f[0]._writeTimer)}f[0]._writeTimer=setTimeout
  47. //替换 if(K.keyCode=="13"){I._applyfilterfromfilterrow()}if(f[0]._writeTimer){clearTimeout(f[0]._writeTimer)}if(K.keyCode == "13"){/*luoyifan*/ return;}f[0]._writeTimer=setTimeout
  48. //搜索 if(L!=0){H=H.substring(L);if(H.length<1){return false}}}if(j.filtercondition!=undefined){K=j.filtercondition}if(M=="datefilter")
  49. //替换 /*luoyifan*if(L!=0){H=H.substring(L);if(H.length<1){return false}}*/}/*if(j.filtercondition!=undefined){K=j.filtercondition}*/if(M=="datefilter")
  50. widget.on('input propertychange', function (event) {
  51. this.value = this.value.replace(/[^\d\\><=.]/g,"");
  52. });
  53. }
  54. });
  55. break;
  56. case 'date':
  57. $.extend(jqxColumnOpt, {
  58. filtertype: 'range'
  59. });
  60. break;
  61. case 'bool':
  62. $.extend(jqxColumnOpt, {
  63. filtertype: 'bool',
  64. createfilterwidget: function (column, columnElement, widget) {
  65. widget.jqxCheckBox({});
  66. }
  67. });
  68. break;
  69. default:
  70. //判断 formatter 是不是字典
  71. if ($.type(easyuiColumnOpt.formatter) === 'array') {
  72. $.extend(jqxColumnOpt, {
  73. filtertype: 'checkedlist',
  74. createfilterwidget: function (column, columnElement, widget) {
  75. widget.jqxDropDownList({
  76. displayMember: 'text',
  77. valueMember: 'id',
  78. source: easyuiColumnOpt.formatter
  79. });
  80. }
  81. });
  82. } else {
  83. //字符串
  84. $.extend(jqxColumnOpt, {
  85. filtertype: 'textbox',
  86. //createfilterwidget: function (column, columnElement, $dom) {
  87. // //debugger
  88. // //var $dom = $('<input>').appendTo(columnElement);
  89. // //var me = this;
  90. // $dom.jqxInput({
  91. // width: '100%'
  92. // }).css({
  93. // margin: "4px 4px"
  94. // });
  95. //},
  96. //createfilterwidget: function (column, columnElement, widget) {
  97. // debugger
  98. // widget.jqxInput({
  99. // width: '100%'
  100. // });
  101. //}
  102. });
  103. }
  104. }
  105. },
  106. /**
  107. * 表格设置
  108. */
  109. gridOption: function ($dom, easyuiOpt, jqxOpt) {
  110. if (easyuiOpt.filter) {
  111. //需要修改 jqxGrid.filter.js 1989/2001行
  112. $.extend(jqxOpt, {
  113. showfilterrow: true,
  114. filterable: true,
  115. autoshowfiltericon: true,
  116. updatefilterconditions: function (type, defaultconditions) {
  117. switch (type) {
  118. case 'stringfilter':
  119. return ['CONTAINS'];
  120. case 'numericfilter':
  121. return ['GREATER_THAN', 'LESS_THAN'];
  122. case 'datefilter':
  123. return ['EQUAL'];
  124. case 'booleanfilter':
  125. return ['EQUAL'];
  126. }
  127. }
  128. });
  129. } else {
  130. $.extend(jqxOpt, {
  131. filterable: false,
  132. });
  133. }
  134. delete jqxOpt.filter;
  135. }
  136. };
  137. })(jQuery);