Search request data
See original GitHub issueHi,
I have a grid with a toolbar, in which I do not load any data when it is initialised. I overload the onSearch method like this to load data from an url which works fine:
onSearch: function (event, eventData) { w2ui['search'].clear(); w2ui['search'].load('http://127.0.0.1:5000/search/' + eventData.searchValue); }
The parameters requested are: "GET /search/opensuse?cmd=get-records&limit=100&offset=0&sort[0][field]=star_count&sort[0][direction]=desc HTTP/1.1"
I also overload the onReload method like this:
onReload: function (event) { this.toolbar.disable('pull'); var search_value = w2ui['search'].searchData[0].value; w2ui['search'].clear(); w2ui['search'].load('http://127.0.0.1:5000/search/' + search_value); }
But when I retype a search term, or refresh or even clear the search field I get more request parameters like "GET /docker/search/opens?cmd=get-records&limit=100&offset=0&search[0][field]=name&search[0][type]=text&search[0][operator]=contains&search[0][value]=opensuse&searchLogic=OR&sort[0][field]=star_count&sort[0][direction]=desc HTTP/1.1"
I do not get search[0][value]
on my first search or after I clear the search field.
Is this because the grid is empty, so there is nothing to search for?
But why is a request sent when I clear the search field? Is it necessary ?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
No, you only get one parameter
event
(this is the same in 1.4 and 1.5) (x). In 1.5 the event data has a propertyreset
and you would write:onSearch: function (event) { if (event.reset === true) { return; } /* your other code here */ }
In 1.4 there is no reset property, so you have to check the searchData property:
onSearch: function (event) { if (jQuery.isEmptyObject(event.searchData)) { return; } /* your other code here */ }
Optionally, you can also call
event.preventDefault()
and/orevent.stopPropagation()
before you callreturn;
if you want to prevent w2ui from executing the default behaviour.(x) = Well, for backwards compatibility, events do support 2 parameters ( eventData.target, eventData ), but internally it’s really just 1 event parameter object, that’s why I suggest to implement events only with 1 parameter.
Sure !!!