<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Implementing UI5 Search Field for Virtual Elements in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14187669#M4923764</link>
    <description>&lt;P&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Aug 2025 12:39:57 GMT</pubDate>
    <dc:creator>RaminS</dc:creator>
    <dc:date>2025-08-22T12:39:57Z</dc:date>
    <item>
      <title>Implementing UI5 Search Field for Virtual Elements</title>
      <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaq-p/14186379</link>
      <description>&lt;H1&gt;Introduction&lt;/H1&gt;&lt;P&gt;When working with Fiori Elements applications, the out-of-the-box search functionality usually triggers a backend OData filter request. This is great when all the fields you want to search on are persisted in the database.&lt;/P&gt;&lt;P&gt;But what happens when you need to search on a &lt;STRONG&gt;virtual/derived element&lt;/STRONG&gt; (for example, a concatenated display text that doesn’t exist as a real DB field)?&lt;/P&gt;&lt;P&gt;In such cases, backend filtering is not possible. The request fails, or you end up with errors because the field isn’t filterable.&lt;/P&gt;&lt;P&gt;Recently, I faced exactly this challenge. The requirement was to allow the user to search inside a &lt;STRONG&gt;table column&lt;/STRONG&gt; where the field was only derived at runtime.&lt;/P&gt;&lt;P&gt;Here’s how I solved it by replacing the default search with a &lt;STRONG&gt;custom search field&lt;/STRONG&gt; in a UI5 Controller Extension.&lt;/P&gt;&lt;HR /&gt;&lt;H1&gt;Why UI5 Search Field?&lt;/H1&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Default FE search:&lt;/STRONG&gt; Sends a filter request to the backend.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt; My search field was virtual → no DB persistence → backend rejects the filter.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Solution:&lt;/STRONG&gt; Replace the default search with a sap.m.SearchField that applies filtering only on the client side (on already loaded table items).&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;HR /&gt;&lt;H1&gt;Implementation Steps&lt;/H1&gt;&lt;H3&gt;1. Extend the Object Page Controller&lt;/H3&gt;&lt;P&gt;In ObjectPageControllerExtension, override the onAfterRendering method:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;onAfterRendering: function () { 
  this.addSearchFieldToTable();
  this.changeColumnLayout();
}&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;H3&gt;2. Custom Search Field&lt;/H3&gt;&lt;LI-CODE lang="javascript"&gt;addSearchFieldToTable: function () {
    const sId = "ObjectPageSearchFieldId"; // Replace with actual ID
    const oOldSearchField = sap.ui.getCore().byId(sId);

    if (oOldSearchField) {
        // Remove default backend filter binding
        oOldSearchField.getFilter().destroy();

        // Add new SearchField with custom handler
        const oNewSearchField = new sap.m.SearchField({
            placeholder: "{i18n&amp;gt;searchPlaceholder}",
            search: this.onSearch.bind(this)
        });

        oOldSearchField.setFilter(oNewSearchField);
    }
}&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;H3&gt;3. Client-Side Filtering&lt;/H3&gt;&lt;LI-CODE lang="javascript"&gt;onSearch: function (oEvent) {
    const sQuery = (oEvent.getParameter("query") || "").trim().toLowerCase();
    const oTable = sap.ui.getCore().byId("ObjectPageTableId"); // Replace with actual ID

    if (!oTable) return;

    // Reset visibility
    oTable.getItems().forEach(oItem =&amp;gt; oItem.setVisible(true));

    // Empty query → show all
    if (!sQuery || sQuery === "*") return;

    // Filter items by virtual field
    oTable.getItems().forEach(oItem =&amp;gt; {
        const oData = oItem.getBindingContext()?.getObject();
        const sVirtualText = oData?.VirtualConcatenatedText || "";
        const aParts = sVirtualText.split(",").map(a =&amp;gt; a.trim().toLowerCase());

        const bMatch = aParts.some(a =&amp;gt; a.includes(sQuery));
        oItem.setVisible(bMatch);
    });
}&lt;/LI-CODE&gt;&lt;HR /&gt;&lt;H1&gt;Result&lt;/H1&gt;&lt;P&gt;Users can now search by the &lt;STRONG&gt;virtual text field&lt;/STRONG&gt; even though it’s not persisted in the database.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Filtering happens instantly on the UI without backend calls.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Backend remains clean since no invalid OData requests are sent.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;HR /&gt;&lt;H1&gt;Key Takeaways&lt;/H1&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Use &lt;STRONG&gt;client-side filtering&lt;/STRONG&gt; when your search target is a virtual/derived element.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;This pattern can be reused in scenarios where backend filtering isn’t possible (e.g., calculated fields, concatenated strings, or UI-only attributes).&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 05:23:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaq-p/14186379</guid>
      <dc:creator>Ram-Gnanesh</dc:creator>
      <dc:date>2025-08-22T05:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing UI5 Search Field for Virtual Elements</title>
      <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14186399#M4923619</link>
      <description>this is just a little better than nothing.......</description>
      <pubDate>Thu, 21 Aug 2025 12:27:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14186399#M4923619</guid>
      <dc:creator>junwu</dc:creator>
      <dc:date>2025-08-21T12:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing UI5 Search Field for Virtual Elements</title>
      <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14187669#M4923764</link>
      <description>&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Aug 2025 12:39:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14187669#M4923764</guid>
      <dc:creator>RaminS</dc:creator>
      <dc:date>2025-08-22T12:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing UI5 Search Field for Virtual Elements</title>
      <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14187670#M4923765</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;With all due respect&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.sap.com/t5/user/viewprofilepage/user-id/1704616" target="_blank" rel="noopener"&gt;@Ram_Gnaneshwaran_Babu&lt;/A&gt;&amp;nbsp;this is a very bad idea. The whole concept behind Hana and the SADL framework is to allow the database layer to do all the filtering, pagination, sorting, etc. Front-end filtering would only work in a very restricted situations.&lt;/P&gt;&lt;P&gt;Let's say a user does a search that matches 200,000 records in the database. The Fiori framework returns the first 20 records (or whatever the default result-set maximum is). Your front-end filtering then filters out 5 of the 20 records returned from the backend and displays 15 records. The user will then think there were only 15 records matching their query. They never get to see the next 20 result set, or the rest of the 200,000 matches.&lt;/P&gt;&lt;P&gt;For your front-end filtering to work correctly, you will need to force the backend to return all 200,000 matches. And that breaks the principle of the Fiori application framework.&lt;/P&gt;&lt;P&gt;You should at least mention that this&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;only works if the total number of matches is very small&lt;/STRONG&gt;, ie less than number of each result-set returned from the backend.&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Aug 2025 12:39:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14187670#M4923765</guid>
      <dc:creator>RaminS</dc:creator>
      <dc:date>2025-08-22T12:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Implementing UI5 Search Field for Virtual Elements</title>
      <link>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14191061#M4923963</link>
      <description>Thank you for pointing this out — you are absolutely right that, in general, filtering, sorting, and pagination should always be pushed down to the backend. The Fiori framework and SADL are designed exactly for that purpose, and client-side filtering can indeed lead to misleading results when working with large datasets. In my scenario, however, the requirement was a bit different: the field in question is a virtual/derived element that does not exist in the database and is therefore not filterable through OData. Because of that limitation, backend filtering isn’t an option in this case. The table in which this requirement applies also has a relatively small result set (object-page level, scoped context), which makes client-side filtering practical and safe. That said, I fully agree that this approach should only be considered for small datasets and when backend filtering is not possible. For larger datasets, backend-driven filtering remains the best practice.</description>
      <pubDate>Mon, 25 Aug 2025 12:06:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/implementing-ui5-search-field-for-virtual-elements/qaa-p/14191061#M4923963</guid>
      <dc:creator>Ram-Gnanesh</dc:creator>
      <dc:date>2025-08-25T12:06:52Z</dc:date>
    </item>
  </channel>
</rss>

