2

Is it possible in jLinq to sort my data according to a defined function?

I would like to have something like:

var res = jLinq.from(data).orderBy(function (r) { return r.x + r.y; }).select();

Currently I have implemented this solution

var index = function (r) { return r.x + r.y; };

var res = jLinq.from(data).select();
res.sort(function(a,b){ return index(a)<=index(b) ? 1 : -1; });

but I was wondering if it is feasible in jLinq before the select

Roberto
  • 504
  • 11
  • 23

2 Answers2

2

This library provides what you are looking for http://linqjs.codeplex.com/

Houssam Hamdan
  • 888
  • 6
  • 15
0

You could add a computed column to your query and sort by that. Take a look at this post: Get sum of two columns in one LINQ query

Community
  • 1
  • 1
Rob
  • 11,492
  • 14
  • 59
  • 94
  • In order to apply your solution it is necessery to map my object into "obj + index". I don't know if it is possible to do it in jLinq and however this sounds like a workaround.. does it means that there is no way to do it in a more direct (and elegant) way? – Roberto Jun 14 '13 at 08:32