Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A simple Sort By Column function #213

Open
JesseDahl opened this issue Oct 10, 2013 · 1 comment
Open

A simple Sort By Column function #213

JesseDahl opened this issue Oct 10, 2013 · 1 comment

Comments

@JesseDahl
Copy link

I've just started using this library recently, so I may just not be using it correctly yet. I was looking for a concise way to sort by a column without having to write a comparator function each time I called it, so I wrote this:

Miso.Dataset.prototype.sortByCol = function(column) {
    return this.sort(function(rowA, rowB) {
        if (rowA[column] < rowB[column]) { 
            return -1; 
        }
        if (rowA[column] > rowB[column]) { 
            return 1;  
        }
        return 0;    
    });
};

I was wondering if:

  1. I'm just missing something in the API, and there is already an easy/concise way to sort by column
  2. If not, is this something that you might want to add to the API?

Also, I'm not sure if this hack works if the column ends up being an object instead of just a basic type. Haven't tested it out yet.

@protobi
Copy link

protobi commented Oct 24, 2013

Neat extension .. maybe the seed for a Miso plugin project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant