Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
May 10, 2022 1:43:00 PM
Aug 17, 2021 8:37:09 AM
You can build a search capability using methods like searchResults() and the selectAssociations(). The difference these methods is highlighted in "search functionality with Qlik Sense Engine API " .
Below extract uses searchResults() and the selectAssociations() methods
app.searchResults([$(this).val()],
{qOffset:0, qCount: 15},
//limiting search to field Country
{qSearchFields: ['Country'], qContext: 'CurrentSelections'},
//{qContext: 'CurrentSelections'},
function(reply){
$(".qs-search-results").html("");
if (reply.qResult.qTotalNumberOfGroups === 0){
return;
};
$(".qs-search-results").append("<ul>");
var searchResults = reply.qResult.qSearchGroupArray;
searchResults.forEach(function(result, i){
result.qItems.forEach(function(item){
$(".qs-search-results ul").append("<li data-index='" + i + "'>");
$(".qs-search-results ul li:last-child").append("<div class='qs-search-item-identifier'>" + item.qIdentifier + "</div");
var matchString = "";
item.qItemMatches.forEach(function (match) {
matchString += match.qText;
});
$(".qs-search-results ul li:last-child").append("<div class='qs-search-item-string'>" + matchString + "</div>");
});
});
$(".qs-search-results li").click(function() {
app.selectAssociations($(this).data("index"), [$(".qs-search").val()], {qContext: 'CurrentSelections'});
$(".qs-search").val("");
$(".qs-search-results").html("");
});
});
A complete demo can be found in Custom Search Functionality in Capability APIs or attached & tested mashup sample "searchResultAPIEx".
From the attached mashup searchResultAPIEx, we noticed that, even if a field in source qvf is AUTO sorted or sorted alphabetically, the result of searchResults method is sorted by STATE.