Provide a search component for users to search for the required data. Data is fetched from reports based on the search keyword.
Use Case
A library or a book management system wants to allow for searching. Any customer who wants to search for a particular genre of books can do so easily with the available category listings under the main search.
Steps to follow
2. Rename the
created
form
to
'Book'
and the report to
'Books'.
3. We shall now
create a function
to get
all the genres of the
Books
uploaded. We'll use this listing to show our category listing.
4. Add the below
Deluge code in the
Deluge editor to get the genres.
-
list getGenres()
-
{
-
-
//return a list of genres, hence return type is list
-
//get all distinct genres available
-
genres = Book[ID != null].Genre.getAll().distinct();
-
return genres;
-
}
The above code will return the list of all distinct genres available.
5. Let's
create a page
now for searching books and name it
Search for books.
6. Drag a search element and mark the placeholder as
Title/Author. Click the
Configure
icon and select the
Search result component
as
Report
and select the
Books
report.
7. Set the criteria to search the
Books
report for the search string in title or author.
The configuration of the search element is as follows:
8. Drag an
HTML snippet
below the Search Element.
9. Let's create a list of the genres with corresponding links to the
Books
database filtering records that match the current genre.
-
<%{
-
//Get all the genres from function created in Step 3 & 4
-
genres = thisapp.getGenres();
-
for each genre in genres
-
{
-
%>
-
<!- Create an HTML anchor tag to the Books report filtering appropriately -->
-
<a class="genre-link" href="#Report:Books?Genre=<%=genre%>"><%=genre%></a><br/>
-
<style>
-
<!-- Style for the anchor tags -->
-
a.genre-link {
-
display: inline-block;
-
width: 115px;
-
height: 25px;
-
padding: 10px;
-
padding-left: 20px;
-
text-align: left;
-
border-radius: 5px;
-
font-weight: bold;
-
line-height: 25px;
-
}
-
</style>
-
<%
-
}
-
}%>
10. Finally, although optional, we shall
publish the
Search for Books
page and
Books
report to make it available for all users to search and check the availability.
See how it works