AngularJS: Hide Row in NG-Grid Based on Condition

I am a beginner in angularJS and I have a requirement to hide a row in my ng-grid table if the value of a column is '0'.

The grid consists of 4 columns:

  • User
  • Today
  • This Week
  • This Month

I need to hide an entire row if the value in the 'This Month' column is '0'

The HTML for the grid is as follows:

<div data-ng-controller="workflowworkitemscompleted as vm">
    <div data-ng-if="isbusy">
        <div data-cc-spinner="vm.spinnerOptions"></div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="gridStyle" style="height:157px" data-ng-grid="gridOptions" id="cwigrid"></div>
        </div>
    </div>
</div>

The controller code is shown below:

$scope.searchfilter = "";
    $scope.mySelections = [];
    $scope.sortInfo = { fields: ['countDay'], directions: ['desc'] };
    $scope.totalServerItems = 0;
    $scope.pagingOptions = {
        pageSizes: [5],
        pageSize: 5,
        currentPage: 1
    };

    $scope.gridOptions = {
        data: 'wfiprocessed',
        multiSelect: false,
        rowHeight: 25,
        showFooter: false,
        footerRowHeight: 40,
        enableColumnReordering: false,
        showColumnMenu: false,
        enableColumnResize: false,
        enableRowSelection: false,
        filterOptions: $scope.filterOptions,
        selectedItems: $scope.mySelections,
        enablePaging: false,
        pagingOptions: $scope.pagingOptions,
        plugins: [gridLayoutPlugin],
        totalServerItems: 'totalServerItems',
        sortInfo: $scope.sortInfo,
        useExternalSorting: false,
        virtualizationThreshold: 50,
        rowTemplate: "<div ng-style=\"{ 'cursor': row.cursor }\" ng-repeat=\"col in renderedColumns\" class=\"ngCell {{col.colIndex()}} {{col.cellClass}}\">" +
            "   <div class=\"ngVerticalBar\" ng-style=\"{height: rowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\">&nbsp;</div>" +
            "   <div ng-cell></div>" +
            "</div>",
        columnDefs: [
            { field: 'userName', displayName: 'User', cellTemplate: vm.optimizedcell },
            { field: 'countDay', displayName: 'Today', cellTemplate: vm.optimizedcell },
            { field: 'countWeek', displayName: 'This Week', cellTemplate: vm.optimizedcell },
            { field: 'countMonth', displayName: 'This Month', cellTemplate: vm.optimizedcell }
        ]
    };

The table displays like this:

After analyzing the table, it is clear that the 'dtealdev' or 'qauser2' rows should not be visible as the 'This Month' column value is '0'

Answer №1

Within your $scope.gridOptions data source, you populate the grid with all the necessary datasets to display. However, it appears that you are including unwanted fields such as 'qauser2' and 'dtealedev' in this dataset.

To rectify this issue, you should only return the specific set of data values that are required for displaying.

$scope.gridOptions.data = function(data) {
    // Filter out items in data that have 0 in all fields
   
    return newData;
}

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

A perfect illustration showcasing the distinction in practical applications for the operators `=` and `&`

Although I grasp the technical distinction between using = and & in isolated scopes, such as understanding what is assigned to isolate scope property: // "=" isolateScopeProperty = getter(parentScope) // "&" isolateScopeProperty = function(locals ...

Is it advisable to compress my API response in PHP?

At this stage, I find myself needing to generate extensive reports in order to gain a better understanding of the data at hand. To do so, I must retrieve one of my tables which contains around 50 parameters and 40,000 rows. While fetching the data via API ...

Setting up a secure Node.JS HTTPS server on Cloud9 IDE

Wondering if it's possible to set up a Node.js https server in the cloud9 IDE? Check out this example of a basic https server setup in Node.js. var https = require('https'); var fs = require('fs'); var app = require('./app& ...

Make a quick call to the next function within the error handling module for a

Currently, I am facing an issue while trying to call the next function within the error handler of my node + express js application. In each controller, I have a middleware known as render which is invoked by calling next, and I wish to achieve the same f ...

The user removal process is not functioning properly

I'm encountering an issue in my Angularfire project while trying to remove a user. The email and password are being passed correctly, but the method responsible for user removal isn't getting executed. Below is the snippet of code from my Authent ...

What is the best way to implement auto-refreshing with reactQuery?

Hey there! I'm currently working with a GraphQL API and I'm trying to automatically refetch data at regular intervals (e.g. every 3 seconds). I've been using React Query and have tried some workarounds like using setInterval, but it's n ...

The Ubiquity CmdUtils.setSelection function does not support replacing HTML code

I'm working on a Ubiquity command to replace selected links or URLs pointing to images with the actual image itself. However, I've found that the CmdUtils.setSelection() function doesn't work when there are html tags in the selection, render ...

Unable to change the variable for the quiz

Currently, I am in the process of developing a quiz app and I am facing an issue with my correct variable not updating. Whenever I trigger the function correctTest() by clicking on the radio button that corresponds to the correct answer, it does get execut ...

What steps should I take to fix the error occurring in my MEAN project?

I'm encountering an issue while trying to run grunt "Cannot find module './api" The error points to the 'routes.js' file --->click here for a visual representation of the project's structure. app.use('/api/things', ...

How to create a CSS animation that gradually darkens a background image during a

Currently in the process of constructing a page with an intriguing background image: body { background:url(images/bg.png) center center no-repeat fixed; -webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; ...

Doubt surrounding the behavior of Node.js when a file is required that does not export anything from a module

My understanding of Node.js' require() function and module.exports is high-level, but I still find some behaviors confusing. Imagine I have two simple one-line files named a.js and b.js. In a.js: require('./b.js'); and in b.js: console. ...

Ways to switch visibility based on user's selection

Currently, I am working on a project that involves a select form with multiple options. However, I need to display a specific div only when a particular option is selected. Can anyone suggest the best solution for this scenario? Your guidance would be grea ...

Using data fetched from PHP in HTML via jQuery post: A step-by-step guide

I have created a function in jQuery that uses $.post to send data to a PHP file. The query in the PHP file is working fine and returning the data back successfully. JavaScript code: function send_agenda_data(cidade_data){ var data = {'cidade_dat ...

Utilizing Intellij for modifying .js files leads to encountering Jshint errors

Currently, I am working on a web project created by Yeoman in Intellij 12.1.6. Every time I update files, JSHint runs and I keep receiving multiple warnings like these: line 11 col 10 Expected 'restrict' to have an indentation at 9 instead a ...

What is the reason for Rich file manager to include filemanager.config.json instead of simply adding an image to the text

I have integrated Rich File Manager with Laravel 5.3.20 using the default configuration provided below: Javascript <script> CKEDITOR.replace( 'textarea', { filebrowserBrowseUrl: '{!! url('gallery/index.html& ...

"Error 404: Invalid request encountered while using React and

I am encountering an issue with a 404 not found error when I attempt to send a post request in React. My code involves using Django Rest Framework on the backend and React Axios on the frontend, but I am facing errors while making the post request. Below i ...

"Confusion arising from the $get method in an Angular

My understanding of providers is a bit unclear. Could someone clarify for me why I am unable to access the "setText" provider function from the controller? It seems that I can only access functions within the $get block. var myMod = angular.module(' ...

The NodeJS server encountered an issue when attempting to load the JavaScript modules

Hey everyone. I'm currently using Node.js and Express.js for the back end of my web application, but I keep running into issues with the server trying to bind references in the source code. Here's the structure of my app: src/ - static/ - ...

Utilizing an ajax request to invoke a PHP function rather than using a traditional

Within my page, I have included a file named functions.js. In this file, there is a line that reads: ajaxRequest.open("GET", "save.php?json=" + jsonstring + "&rand=" + rand, true); How can I invoke a php method using ajaxRequest? Additionally, I woul ...

Having trouble with babel-loader, encountering an issue with UglifyJS (ES6) causing errors

Recently, I integrated the FlipClockJs vue component into my project and it was functioning properly during development when I executed yarn encore dev However, upon running yarn encore production An error cropped up as follows: ERROR Failed to ...