Tips for Using AngularJS to Filter End DatesI'm trying to figure out how to filter

Hey everyone, I'm looking to filter items based on a date range (Start and End Date), specifically using the daterange functionality in my meanjs app. Check out My Plunk for reference.

  • Please take a look at my plunker for more context.

  • I am displaying the Due_date, which is the field I want to filter with.

  • I have utilized some functionality to calculate invoice_Date and terms to derive the Due_date. For example, if invoice_date is 2016-09-10 and terms are 6, then the resulting Due_date would be 16-09-2016.

  • What I am seeking is to filter the transactions based on the Due_date within a specified start and end date. For instance, if we select a start date of 16-09-2016 and an end date of 25-09-2016, only those two transactions should be displayed in the table. This is why I've implemented the daterange filter solution.

  • I can successfully filter by start date, but experiencing issues filtering by End date. For example, if the startdate is 16-09-2016 and the end date is set to 28-09-2016, three transactions should be displayed, but currently only two are appearing in the table. See My Plunker for details.

Controller:

 .filter("myfilter", function() {
   return function(items, from, to) {
     var df = from;
       var dt =to;
         var result = [];   

      for (var i=0; i<items.length; i++){
        var date = new Date(items[i].invoice_date);
          date.setDate(date.getDate() + parseInt(items[i].terms));
           var tf = date;
             if (tf > df && tf < dt)  {
               result.push(items[i]);
            }
        }   
         console.log(items);
        return result;
  };
});

Html:

<input type="date" class="form-control" name="from" ng-model="from">

<input type="date" class="form-control" name="to" ng-model="to">

Filter:-

ng-repeat="data in  record | myfilter:from:to"

The following field needs to be filtered in the table:

Due_date:-

<td> {{addDays(data.invoice_date,data.terms) | date:'dd-MM-yyyy'}}</td>
  • For further guidance, refer to my plunker: My plunker

Answer №1

For all your datetime operations, I recommend using Moment.

var date = moment(items[i].invoice_date).add(items[i].terms,'d');
if(date.isAfter(from) && date.isBefore(to)){
  .....
}

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

The FormidableJS form encounters parsing issues when submitted through AngularJS

I have encountered an issue while posting to a formidable form from AngularJS. The form does not parse, and I suspect it might have something to do with the lack of express.bodyParser(). Server-side: ... var form = new formidable.IncomingForm(); console. ...

Executing a JavaScript function when an HTML page is loaded within an OBJECT Tag

I have a situation where I am loading an HTML page inside an object tag. Since the iPad does not support iFrames, I decided to use the object tag to load external HTML pages into a container. Everything is working well so far, but now I want to be able t ...

How to create a Vue.js animated navbar with scroll opacity

I am looking to create a fixed navbar that changes opacity based on user scrolling behavior. Initially, I want the navbar background to be transparent and then transition to white as the user scrolls down the page. An example of what I am trying to achieve ...

Creating a layout with Bootstrap 4 cards split into two rows

I need to change my layout from 3 columns to 2 columns. I know I can achieve this using CSS like the code snippet below, but I'm curious if there's a built-in Bootstrap method for this: .card-columns { -webkit-column-count: 2; -moz-column-co ...

Design user interface utilizing object with arrays of nested objects

Is it possible to create a dynamic user interface in Angular based on complex nested objects? While ng-repeat works well for simple arrays and objects with elements of the same type, I am looking for a way to build UIs dynamically using objects that conta ...

Is it possible to condense my angular-ui-router stateProvider definition?

While Angular-UI-Router is a great tool, I find that my code for defining the stateProvider is getting repetitive. For example: .state('home', { url: "/home", templateUrl: "home.html" }) .state('products', { url: "/products", t ...

Troubleshooting Bootstrap's Margin Problem

Currently, I am delving into the basics of bootstrap and encountering some challenges with using margin-auto. Specifically, I am working on positioning a navbar by using ml-auto to separate it from the brand, pushing the navbar to the right side of the p ...

Issue: [ng:areq] The function 'DepartmentCustomReportController' is missing and undefined in Internet Explorer

I am encountering an issue specifically in Internet Explorer, as the same controller works without any problems in Chrome. Here is a snippet of my index.html file: <script src="assets/js/boostrapJs/jquery-1.11.1.min.js"></script> <script s ...

How can you automatically adjust the height of a div to be 100% of its parent while maintaining top and bottom margins

http://jsfiddle.net/YumHS/ The page showcased in the provided jsfiddle link includes a sidebar within the content div. <section class="cont"> <div class="sidebar"> <ul> <li> ...

Achieving consistent margins across various browsers for UL elements

UL element margins are the same, but Firefox and IE are displaying differently. FULL CODE: <html> <head> <style> body { background-color: Red; } ul ...

Angular Sliding User Interface

Hello everyone, I'm currently working on implementing the angular-ui slider feature, which you can find at this link: https://github.com/angular-ui/ui-slider After including jquery, jquery-ui, and angular files, as well as the necessary CSS files, I ...

Utilizing the modulo operation for organizing rows and columns

I’ve seen this question asked many times, but I’m still struggling to figure it out. The examples I’ve come across are either too complex or involve Angular or Javascript. My goal is to learn how to set up 4 columns within a row. // initiating a ...

Ways to disable the ability to close a bootstrap modal by pressing the backspace key

How can I enable the backspace button in a Bootstrap Modal form for textboxes and textareas? $('body').keydown(function (e) { if ($('#myModal').is(':visible')) { if (e.keyCode == 8) { retu ...

Transferring data between controllers using AngularJS: A step-by-step guide

Here is a snippet of JSON data from my playlist controller: { "id":18, "file":{"url":"/uploads/playlist/file/18/01_-_MashAllah.mp3"}, "event_id":23,"created_at":"2015-11-11T10:33:52.000Z", "updated_at":"2015-11-11T10:33:52.000Z", "name ...

The utilization of CSS variables within intricate properties

Imagine having a CSS property called box-shadow: box-shadow: 5px 5px 0 #ccc; What if there is a need to create a variable from the color #ccc? While in SCSS, you could accomplish this with code like: $grey: #ccc; .element { box-shadow: 5px 5px 0 $gre ...

Opacity transition in CSS does not function properly on a sibling selector when hovering over an element

I have created a responsive menu where the list items after the 4th element are set to display:none; opacity:0 on mobile devices. The 4th element is an icon and when you hover over it, the hidden menu items appear as a block list below using li:nth-child( ...

Using AngularJS to bind events on key presses

Currently, I am working on an SVG application using AngularJS. We are in the process of making a few adjustments to fully support our internal browser, but so far everything seems to be functioning properly. Feel free to check out my demo: http://jsfiddle ...

Tips for displaying or concealing a div using Angular Js

I have set up two div elements with a dropdown control in one named div1. I am looking to hide div2 until a value is selected in the dropdown. How can I show or hide a div based on ng-change, ensuring that div2 remains hidden until a value is selected? Cod ...

Executing jQuery on page update can be achieved by utilizing event handlers to trigger

I have implemented jQuery multi-select to enhance the user experience of my Django app's multiselect feature. Upon initially rendering my page, I included the following script to bind any elements with the class 'multiselect' to the jQuery m ...

Can the text value be read and its strings changed?

I need to modify the message inside an H2 element with the code provided below. I want to change the text from No results were found for this query: <em class="querytext"> to "No results were found by hello world!, but the catch is that I cannot di ...