而不是加載所有客戶記錄在表格加載,動態篩選後端數據基於用戶輸入到SuggestBox
。您可以通過實施自定義SuggestOracle
(可能擴展MultiWordSuggestOracle
)來完成此操作。
public class ServerSuggestOracle extends SuggestOracle{
protected DataSource datasource;
protected int startQueryLength;
protected ArrayList<T> suggestions = new ArrayList<T>();
protected boolean isMoreSuggestions = false;
protected int previousQueryLength = 0;
public ServerSuggestOracle(DataSource datasource,int startQueryLength)
{
super();
this.datasource = datasource;
this.startQueryLength = startQueryLength;
}
@Override
public void requestSuggestions(final Request request, final Callback callback) {
// start the backend call only if the user types in more than startQueryLength characters.
if (request.getQuery().length() < startQueryLength)
return;
// if the user expands the search or a serach hasn't been carried out, call the backend. Otherwise filte the existing list
if (isMoreSuggestions || previousQueryLength > request.getQuery().length() || suggestions.size() == 0)
{
datasource.fetchDataFromBackend(request.getQuery(), new FetchDataFromBackendCallback() {
@Override
public void onFetchData(ArrayList<T> genes,Integer count,boolean isMore) {
suggestions.clear();
for (int i = 0;i<genes.size();i++) {
Suggestion suggestion = new Suggestion();
suggestions.add(suggestion);
}
SuggestOracle.Response response = new SuggestOracle.Response(suggestions);
isMoreSuggestions = isMore;
if (count != null)
response.setMoreSuggestionsCount(count);
else
response.setMoreSuggestions(isMore);
previousQueryLength = request.getQuery().length();
callback.onSuggestionsReady(request,response);
}
});
}
else
{
super.requestSuggestions(request,cabllack);
}
}
}
感謝您的回覆。 – user3469842