SearchField.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Ext.define('Ext.ux.form.SearchField', {
  2. extend : 'Ext.form.field.Trigger',
  3. alias : 'widget.searchfield',
  4. trigger1Cls : Ext.baseCSSPrefix + 'form-clear-trigger',
  5. trigger2Cls : Ext.baseCSSPrefix + 'form-search-trigger',
  6. hasSearch : false,
  7. paramName : 'query',
  8. initComponent : function() {
  9. this.callParent(arguments);
  10. this.on('specialkey', function(f, e) {
  11. if (e.getKey() == e.ENTER) {
  12. this.onTrigger2Click();
  13. }
  14. }, this);
  15. },
  16. afterRender : function() {
  17. this.callParent();
  18. this.triggerEl.item(0).setDisplayed('none');
  19. },
  20. onTrigger1Click : function() {
  21. var me = this, store = me.store, proxy = store.getProxy();
  22. if (me.hasSearch) {
  23. me.setValue('');
  24. proxy.extraParams[me.paramName] = '';
  25. proxy.extraParams.start = 0;
  26. store.load();
  27. me.hasSearch = false;
  28. me.triggerEl.item(0).setDisplayed('none');
  29. me.doComponentLayout();
  30. }
  31. },
  32. onTrigger2Click : function() {
  33. var me = this, store = me.store, value = me
  34. .getValue();
  35. if (value.length < 1) {
  36. me.onTrigger1Click();
  37. return;
  38. }
  39. var rootNode = store.getRootNode();
  40. var length = rootNode.childNodes.length;
  41. var k=0;
  42. //var h=0;
  43. for (var i = 0; i < length; i++) {
  44. var id = rootNode.childNodes[0+k].get('id');
  45. var subRootNode = store.getNodeById(id);
  46. var len = subRootNode.childNodes.length;
  47. var h=0;
  48. for (var j = 0; j < len; j++) {
  49. //var h=0;
  50. var text = subRootNode.childNodes[0+h].get('text');
  51. var subId = subRootNode.childNodes[0+h].get('id');
  52. var subChildNode = store.getNodeById(subId);
  53. if ((text.indexOf(value)) == -1) {
  54. subRootNode.removeChild(subChildNode, false);
  55. }else{
  56. h=h+1;
  57. }
  58. //if()
  59. // if(subRootNode.childNodes.length<1){
  60. // rootNode.removeChild(subRootNode,false);
  61. //
  62. // }
  63. // else{}
  64. // if(subRootNode.childNodes==null){
  65. // rootNode.removeChild(subRootNode,false);
  66. //
  67. // }
  68. }
  69. if(subRootNode.childNodes.length<1){
  70. rootNode.removeChild(subRootNode,false);
  71. }else{
  72. k=k+1;
  73. }
  74. }
  75. // for (var h = 1; h < rootNode.length; h++) {
  76. // var id2 = rootNode.childNodes[h].get('id');
  77. // var subRootNode = store.getNodeById(id2);
  78. // if (subRootNode.childNodes.length < 1) {
  79. // rootNode.removeChild(subRootNode, false);
  80. // }
  81. // }
  82. me.hasSearch = true;
  83. me.triggerEl.item(0).setDisplayed('block');
  84. me.doComponentLayout();
  85. }
  86. });