↓ Skip to main content
A watercolour of two hands holding a round wooden sieve over a teal bowl. Thirteen teal beads lie in the sieve. Three orange beads have fallen through and lie in the bowl.

Search and Filtering

A list of 1,483 work orders is of little use until the user can narrow it. A datasource offers three ways to do that: a text search, a filter by column, and a filter in memory. They look alike in code. Two of them ask Maximo, and the third one sees only the rows the app has already loaded.

MAS 9.2 series guide

We ran every call of this guide on our test system, on the MAS 9.2 series, on a page of our Components Explorer, and read the request each call sent. Saved Queries and Filters covers the queries a datasource is declared with. This guide covers what your code and your user do at runtime.

The datasource of this guide
#

<maximo-datasource id="fs_d_search_ds" object-structure="mxapiwodetail"
    where="siteid=&quot;BEDFORD&quot;" order-by="wonum" page-size="10" selection-mode="none">
  <schema id="fs_d_search_ds_s">
    <attribute name="wonum" unique-id="true" searchable="true" id="fs_d_search_ds_a_wonum"/>
    <attribute name="description" searchable="true" id="fs_d_search_ds_a_description"/>
    <attribute name="status" id="fs_d_search_ds_a_status"/>
    <attribute name="wopriority" id="fs_d_search_ds_a_wopriority"/>
    <attribute name="location" id="fs_d_search_ds_a_location"/>
  </schema>
</maximo-datasource>

Two attributes carry searchable="true". That marks the columns a text search looks into. Every request of this datasource names them, with or without a search:

searchAttributes=wonum,description
Three phone frames of the page “Data: search and filters”. Left, after search(“pump”): the line “Last call: search(“pump”) on fs_d_search_ds: 10 rows of 46”, totalCount 46 and currentSearch pump. Middle, after a filter on status APPR on top of the search: 9 rows of 9, currentSearch still pump. Right, the list of the page with its count “46 records”, the word pump in its search box, and work orders such as 1002 Rebuild Feedwater Pump.
A search, a filter on top of it, and the list with its search box

Search for a text
#

const ds = this.page.findDatasource('fs_d_search_ds');
await ds.search('pump');

The call sent one request. It is the request of the datasource with one more parameter:

oslc.where=siteid="BEDFORD"
searchAttributes=wonum,description
oslc.searchTerms=pump

Maximo searched all 1,483 work orders of the site and answered that 46 match. The datasource keeps the text in its state, as currentSearch.

CallWhat we saw
search("pump")1 request, 46 work orders
search("1221")1 request, 1 work order: the number is a searchable attribute too
search("pump", ["description"]), as the first search1 request with searchAttributes=description, 46 work orders
the same text a second time0 requests
search("")1 request without oslc.searchTerms, all 1,483 again

The second argument narrows the search to some of the searchable attributes, for that one call. The fourth row has a trap. We called search("pump") and then search("pump", ["description"]), and the second call sent nothing. A search with the text the datasource already holds does not run again, also when the list of attributes differs.

An attribute can also carry search-type="WILDCARD". We gave the description that attribute on a second datasource and searched for “pump”. The request and the 46 work orders were the same.

The search box of a list
#

A data-list draws a search box with show-search="true". It uses the same search:

<data-list id="fs_d_search_list" datasource="fs_d_search_ds" no-select-behavior="true"
    show-search="true" show-count="true">

We typed “pump” into the box. Typing alone sent nothing. The Enter key sent the same request as search("pump") in code, with oslc.searchTerms=pump.

The box and the code share one state. After a search("pump") from a button, the box of the list showed the word pump, and the count above the list read “46 records”.

Filter by a column
#

A text search looks into the searchable attributes. A filter by column takes one attribute and one value. The calls are setQBE and searchQBE, for query by example:

ds.setQBE('status', '=', 'APPR');
await ds.searchQBE();

setQBE only stages the filter. searchQBE sends the request, and the filter arrives in the where clause:

oslc.where=siteid="BEDFORD" and status="APPR"

318 work orders matched. A second setQBE on another column adds to the first:

ds.setQBE('wopriority', '=', 1);
await ds.searchQBE();
oslc.where=siteid="BEDFORD" and status="APPR" and wopriority=1

Nine work orders were left. To drop all filters, clear them and search again:

ds.clearQBE();
await ds.searchQBE();

Saved Queries and Filters lists the operators of setQBE and what each one sends.

Search and filter together
#

The two are independent, and they combine. We searched for “pump” and then filtered on the status. One request carried both:

oslc.where=siteid="BEDFORD" and status="APPR"
oslc.searchTerms=pump
StepWork orders
search("pump")46
then a filter on status = APPR9
then search("")318, the filter stays
then clearQBE() and searchQBE()1,483

The nine here and the nine of the last section are two different sets, equal in size by chance. Clearing one of the two leaves the other in place. In the other order it is the same: with a search and a filter active, clearQBE() and searchQBE() brought back the 46 work orders of the search.

So a page with a search box and filter buttons needs no code that joins the two. Each control calls its own method, and the datasource builds the request.

Filter in memory
#

The third way sends no request. applyInMemoryFilter takes a function and keeps the rows for which it returns true:

ds.applyInMemoryFilter((item) => item.status === 'APPR');

It looks only into the rows the datasource has loaded. Our datasource held the first ten of 1,483 work orders, and none of the ten is approved. The list became empty, although 318 approved work orders exist in Maximo. The state then read totalCount = 1473: the count of Maximo minus the ten hidden rows.

clearInMemoryFilter() brought the ten rows back, again without a request.

A text search can run in memory too, with true as the third argument:

await ds.search('pump', undefined, true);

It behaved like the filter. It looked into the ten loaded rows, found no pump there, and emptied the list, while Maximo knows 46. One more detail took us a while to see: search("") did not undo it. It sent no request, and the list stayed empty. clearInMemoryFilter() brought the rows back.

Use the in-memory calls where the datasource holds every row it can ever have: a short list of choices, or the rows of a json-datasource. For a table of Maximo that is larger than one page, search and filter on the server.

The same calls on a json-datasource
#

A json-datasource answers search, setQBE and searchQBE as well, and all of them run in the memory of the app. Our demo datasource has ten rows:

CallRowsRequests
search("pump")30
then a filter on status = APPR0, no pump row is approved0
then clearQBE() and searchQBE()30
then search("")100

A list with a search box works on it the same way. Maximo-Datasource vs. JSON-Datasource compares the two kinds.

Which one to use
#

You wantUse
the user types a wordshow-search="true" on the list, with searchable attributes
a search from a button or a scansearch(text)
a filter on one column: a status, a priority, a datesetQBE and searchQBE
a filter the app always haswhere or a saved query in the declaration
to narrow a short list that is loaded completelyapplyInMemoryFilter

What to read next#

Pagination and Performance shows what a request costs with a small and a large page. The cookbook recipe Add a Lookup Field uses the same server-side search inside a lookup.


IBM documents searchable, search-type and show-search in the product itself. In the Application Configuration application, open the ? menu and choose Component Documentation for attribute and data-list.