Sorting by order of days is accurate, but sorting by months is incorrect

Attempting to organize my data using the ng-repeat option below:

ng-repeat="date in dateList | orderBy:'dateObject':false"

Each dateObject holds a Date object corresponding to the date.

Initially, the output appears correct:

22-03-2017
23-03-2017
24-03-2017
Etc.

However, when I add dates from the following month, strange ordering occurs:

01-04-2017
02-04-2017
03-04-2017
04-04-2017
22-03-2017
23-03-2017
Etc.

It perplexes me why the sorting is inconsistent between months and days...

Answer №1

To organize the data in your controller, you can utilize a filter to ensure it is formatted in a way that allows for alphabetical sorting.

$filter('date')(date.dateObject, 'yyyy-MM-dd')

Alternatively, you can implement a custom sorting function:

$scope.myValueFunction = function(date) {
   return $filter('date')(date.dateObject, 'yyyy-MM-dd')
};

Afterwards, apply this function within your HTML:

ng-repeat="date in dateList | orderBy: myValueFunction"

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

Adding options to a dropdown menu dynamically while editing a form with the help of javascript

I have a dropdown like in below:- <form name="depositForm" action="<?php echo site_url('ajax_funds/deposit_funds'); ?>" id="depositForm" class="page-form-main form-horizontal " autocomplete="off" method="post"> <div class="form- ...

Menu with customized hover feature, revealing submenu upon mouse movement

I have implemented my own hover event handler to display a triangle pointer and a horizontally aligned submenu bar. It works well for showing and navigating to the submenu when the top menu item is clicked. However, I am facing an issue where the submenu b ...

What could be preventing data from properly binding to my AngularJS component?

I want to create an AngularJS component called messageDisplay. This component should be able to accept a property named message, which will be provided directly in the HTML tag of the index.html file, and then display that message. Despite following variou ...

Experience the convenience of running Javascript code directly within the editor of Intellij IDEA

After spending a lot of time writing code in the Ultimate edition of Intellij Idea, I find myself frequently needing to test methods or large code sections. I often find myself copying and pasting code into Firebug in Firefox, which is a small and cramped ...

Is there a way to access the value of a textBox within an AJAX method?

Upon clicking the Log In button, I am faced with two issues. Firstly, when prompted by localhost to allow access, the pop-up disappears in a split second after one click. Only upon double-clicking does it persist at the bottom of the screen, allowing the A ...

An error in JavaScript occurred when trying to hover the mouse using Robot Framework: The method "elementsFromPoint" is not allowed on ShadowRoot

When attempting to mouse hover on an element using Robot Framework's keyword Mouse Over, I encountered an error stating, "javascript error: Disallowed method "elementsFromPoint" on ShadowRoot.". Interestingly, other keywords such as Click Element work ...

The jQuery autocomplete feature with typeahead suggestions fails to appear following a successful AJAX request

I am currently using typeahead.js to incorporate tags into my multiple input setup. The tagging function works as expected, however, I am facing an issue where the autocomplete suggestions are not appearing. Is there a solution to fix this problem? Despit ...

Determine the status of the menu in React select by checking on key press events if it is open

In my project, I am utilizing react-select for the select elements. I'm curious if there's a way to detect the "open" or "closed" state of the menu through a keydown event in the select (either on the select input or within the menu). The versi ...

Accessing the i and i+1 elements within a ng-repeat iteration

I'm currently learning Angular and struggling with a seemingly simple issue. My goal is to achieve the following HTML structure in AngularJS: <div> <div> {{bar[i]}} {{bar[i+1]}} </div> <div> {{bar[i+2]}} ...

Identify the quantity of dynamically added <li> elements within the <ul> using jQuery

I'm facing an issue where I need to dynamically add a list of LI items to a UL using jQuery. However, when I try to alert the number of LI elements in this list, it only shows 0. I suspect that it's because the code is trying to count the origina ...

Can you explain the distinction between the terms "vite" and "vite preview"?

I recently created a project template with the help of vite. While looking through my package.json file, I noticed the following section; "scripts": { "dev": "vite", "build": "vue-tsc --noEmit &&a ...

Navigating to a specific path depending on the condition

I am currently developing a small AngularJS application with a login view and a main view that is set up as follows: $routeProvider .when('/main' , {templateUrl: 'partials/main.html', controller: MainController}) .when('/login& ...

You can update a JavaScript string by adding values using the '+=' operator

I have the following function: function generateJSONstringforuncheckedfilters(){ jsonstring = ''; jsonstring = "["; $('body').on('click', 'input', function(){ jsonstring += "[{'OrderGUID&apo ...

React - Incorrect components experiencing style changes due to setTimeout

Check out the code snippet here: https://jsfiddle.net/69z2wepo/204131/ A main component displays two 'notifications' each with different disappearance timings. class Page extends React.Component { constructor(props) { super(props); t ...

Having trouble sending an array from Flask to a JavaScript function

As a newcomer to web development and JavaScript, I'm struggling to pass an array from a Flask function into a JavaScript function. Here's what my JS function looks like: function up(deptcity) { console.log('hi'); $.aja ...

Error: The JS Exception has not been handled, as it is stating that 'undefined' is not an object when evaluating 'global.performance.now' in react-native-tvOS

I am currently working on a React-Native-tvOs app and despite following all the instructions from the react-native-tvOs GitHub page, I keep encountering an error when running the default template app. Even after running the script provided on the GitHub re ...

I am unable to execute Parcel in my project as it is not generating a distribution folder with the compiled file

I'm in need of some assistance in identifying and resolving an error that I'm having trouble understanding. To start, I initialized the project with the command: npm init -y Next, I installed Parcel using: npm install --save-dev parcel I then ...

Experiencing issues with undefined NextJS environment variables?

I've developed a custom script to store some fixed data onto my file system. The script is located at the following path: ./lib/createLinks.js const contentful = require('contentful') const fs = require('fs') require('d ...

Angular is able to select an element from a specified array

I'm currently struggling with using Angular to manipulate a TMDB API. I am having difficulty retrieving an item from an array. Can someone provide assistance? Here is the response that the array returns: { "id": 423108, "results ...

Binding variables in JSX with Vue.js scope involves connecting data directly to the template

I am in search of code similar to this: <div v-for="item in items" :key="item"> {{ item }} ... <div v-with:newValue="calculateValue(item)"> {{ newValue }} </div> </div> I'm not sure what to call this pattern, but ...