Condition-based table data binding

I currently have a table where the column is labeled as {Orders}. In my metadata.xml file, I am retrieving the entity {status}.

    
        <smartTable:SmartTable id="table" beforeRebindTable="handleBeforeRebindTable">
            <Table>
                <columns>
                    <Column>
                        <header>
                            <Text text="ManufacturingOrder" id="order"/>
                        </header>
                    </Column>        
                </columns>

                <items>
                    <ColumnListItem >
                        <cells>
                            <ObjectIdentifier title="{Order}" />
                        </cells>
                    </ColumnListItem>
                </items>
            </Table>
        </smartTable:SmartTable>
    

My goal is to only display orders with a status of 1. (Statuses may vary).

To achieve this, I have implemented the handleBeforeRebindTable function:

    
        handleBeforeRebindTable: function(oEvent) {

            var oTableItems = this.getView().byId("table").getItems();
            var oItemData;
            var sStatus = "status";
            for (var i = 1; i < oTableItems.length; i++) {
                oItemData = oTableItems[i].getBindingContext().getProperty();
                if (this.sStatus === "1") {
                    oTableItems[i].setVisible(true);
                }  else {
                    oTableItems[i].setVisible(!oItemData.Active);
                }
            }

        },
    

Despite my efforts, the code doesn't seem to work properly. Can anyone help me identify what I'm doing wrong or suggest an alternative approach?

Answer №1

Prior to the table binding, the event BeforeRebindTable is triggered, meaning the table will not have any data yet. However, you can include a filter in this event before the binding process.

handleBeforeRebindTable: function(oEvent) {
    var oFilters = oEvent.getParameter("bindingParams").filters;
    oFilters.push(new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "1"));
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Oops! An error occurred while trying to find the _mongodb._tcp.blog-cluster-0hb5z.mongodb.net. Please check your query settings and try again

My free Mongo Atlas cluster suddenly stopped connecting, even though everything was working fine before. Strangely, I can see that data has been collected on the MongoDB website. It's puzzling why this issue occurred and now my entire site won't ...

The map function is malfunctioning when trying to query data from MongoDB

I have multiple mongodb documents structured like this {'_id':'1', 'year':2020, 'season':'Summer', 'status':'Over'}, {'_id':'2', 'year':2020, 'se ...

Is it possible for an element that is styled with 'overflow: scroll' to cause the

I am currently facing an issue with adding a scroll listener to an element that has overflow-y: scroll If you have a div: <div id='my-div'>my div</div> styled like this: #my-div { overflow-y: scroll } The JavaScript code below ...

How can Angular be used to dynamically show or hide an element based on its height?

Is there a way in Angular to display a "Read More" link once the height of a paragraph reaches 200px? I'm looking for an elegant solution. Here are my elements: <section class="mynotes" ng-if="MyController.mynotes"> <p ng-bind="MyController ...

Error in Discord Bot: discord.js showing TypeError when trying to read the length of an undefined property

I'm currently working on developing a Discord bot and using CodeLyon's Permissions V2 video as a guide for reference. There seems to be an issue in my message.js file which contains the following code: require('dotenv').config(); //cre ...

Manipulating CSS styles with jQuery

Trying to update the UL image in the CSS directory using jQuery for a Twitter stream: as tweets are displayed, want to change the avatar of the account associated with each post. Using .css is straightforward, but struggling to modify the URL for the new i ...

Is it possible for an <input> tag in PHP AJAX to have an "action" attribute similar to a <form> tag?

Forms typically use an action attribute to specify where the data should be posted, such as a .php file. Do <input> elements have this action attribute as well? The answer is likely no, but I am curious to understand what concept I may be misunders ...

When using Selenium with Java, interacting with checkboxes produces varying results compared to manually clicking on them

I'm encountering an issue with clicking on a specific checkbox that should be checking all the other checkboxes below it (root parameter). Previously, when using the following code on the element: arguments[0].click(); Attempting to use the regular ...

Displaying the step increment bar by default in a number input using CSS

If I have an input field like this: <input type="number" step="1"> Whenever you hover over the text box, a scrollbar shows up on the right side of the number input. How can I keep it visible at all times? ...

Troubleshooting: EJ Syncfusion React Scheduler Issues

I have recently implemented a syncfusion calendar for managing appointments in my ReactJs project, following the code examples from this link . After editing the JS and CSS codes (available at ), I encountered an issue with the CSS not displaying correctl ...

Jose authentication is encountering issues with verifying JWT

My Next.js/Clerk.js middleware setup looks like this: import { authMiddleware } from "@clerk/nextjs"; import { jwtVerify } from "jose"; export default authMiddleware({ publicRoutes: ["/", "/contact", "/pricin ...

Create a music player application using the React context API

Here is a code snippet for implementing a music player using context: import React from 'react'; import { BarSongTitle, BottomBar, Button, PlayList, Song, SongTitle, } from './styles.js'; import { songList } from './con ...

Determine the number of simultaneous key presses in JavaScript

Is there a way to accurately track the number of keys pressed simultaneously? I've made progress, but encountered issues when tabbing out of my browser window. If I press x amount of keys while tabbing away and then release them in another window, the ...

What is the best method for summing the numerical values of a JSON array?

I have a task to calculate the sum and average of integer values from an Array object. Here is the input array: Input: [ {"string": "John", "integer": 7}, {"string": "Margot", "integer& ...

Error importing React Icons with the specific icon FiMoreHorizontal

Currently following a guide to create a Twitter-like application and I need to add the following imports: import { FiMoreHorizontal } from 'react-icons/fi' 2.3K (gzipped: 1K) import { VscTwitter } from 'react-icons/vsc' 3.1K (gzipped: ...

When using SuperTest, the Authorization header value may unexpectedly return undefined

Currently, I am working on writing tests using Mocha, Supertest, and Chai. In order for my API's to function properly, they require an Authorization header which can be obtained from req.headers["authorization"]. Below you will find the current setup ...

What could be causing this Jquery Ajax failure in Opera and Safari?

I've encountered an issue where this code functions correctly in FF, Chrome, IE6/8 but fails in Safari and Opera. Any insights into what might be causing this discrepancy? Below is the snippet of code in question: var name = $('#esm').val( ...

Trouble with initializing the Ionic map controller

I have a mobile app with 5 tabs, one of which features a map. However, the map only loads when directly accessed through the URL bar. It seems that the controller is not loaded when navigating to the map tab through the app, as indicated by console logs. S ...

Node.js MySQL User Verification

As a beginner in node JS, my current project involves authenticating users against a backend MYSQL database. Below is the code snippet responsible for handling authentication: function Authenticate(username, password, fn) { connection.connect(); ...

Retrieve the name of the selected item in the antd dropdown component

I am facing an issue where I cannot retrieve the name of the select component in Ant Design to use the handleInputChange function on its onChange event. As a workaround, I decided to update the state directly in the onChange event by adding it to an obje ...