Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

179
Vistas
lodash orderBy multiple numeric fields display priority

All is going well using orderBy method when sorting multiple fields on an HTML table. Score A field will be in descending order while Score B field will be in an ascending order. Let's say we have this table with the following data:

Name     Score A     Score B
 A          3
 B                      7
 C          8
 D          1
 E                      2

Using orderBy method:

_.orderBy(scores, ['score_a', 'score_b'], ['desc', 'asc']);

The display would be:

Name     Score A     Score B
 E                      2
 B                      7
 C          8
 A          3
 D          1

However, I want to prioritize the display of a particular field and wanted Score A field to be displayed first instead of Score B. Desired display would be:

Name     Score A     Score B
 C          8
 A          3
 D          1
 E                      2
 B                      7

How to achieve this? Tried also chaining lodash methods. Is this something that should be adjusted on the display? Need your awesome inputs. Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Interchanging 'a' and 'b' score may solve the issue

var scores = [{
    'score': 'a',
    'a': 3,
    'b': 0
  },
  {
    'score': 'b',
    'a': 0,
    'b': 7
  },
  {
    'score': 'c',
    'a': 8,
    'b': 0
  },
  {
    'score': 'd',
    'a': 1,
    'b': 0
  },
  {
    'score': 'e',
    'a': 0,
    'b': 2
  }
];

// Sort by `user` in ascending order and by `age` in descending order.
console.log(_.orderBy(scores, ['b', 'a'], ['asc', 'desc']));
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda