question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom sorting in Data View

See original GitHub issue

I was trying to use a custom sort algorithm in a Data View, because Chrome doesn’t have a stable sort algorithm.

I need to use DataView because I’m doing filtering as well. Since I cannot use the default sort order from the DataView I had to sort the data by myself. I noticed that the DataView has two variables items and rows. The items variable contains all the data inside the DataView. The rows is like a copy of items, but we can do filtering on that which we cannot do on items.

Assuming that I’m correct, If I don’t use filters I could get the items from the DataView sort them and then set again. However, I need to use the rows variable because I want to sort after do some filtering, like in this example

Even though, we don’t have a method to get the rows from a DataView, there is a workaround to get it. I did this:

function getFilteredRows(dataView){
    var rows = [];
    var length = dataView.getLength();
    for (var i = 0 ; i < length ; i++){
        rows.push(dataView.getItem(i));
    }
    return rows;
}

It is important to notice that the name of the method is getItem(i), but the implementation is returning rows[i]. Ok, then I was able to get the rows and do the sort. However, there is no way to set the rows back to the DataView. So I created a method to do that. You can see the code here:

https://github.com/mario-areias/SlickGrid/commit/41a014f7a64a6041ceea461a242546038561e0dc

My questions are: Is this really an issue? There is a way to do this using the Data View api that I didn’t notice? If this is an issue, is this the correct fix?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mario-areiascommented, Aug 13, 2013

Hey,

I read that before post this and I wasn’t able to solve my problem. I thought I could have some explanation here, not just a message with a link. At least, you could point me where is the explanation for that question?

1reaction
mleibmancommented, Aug 13, 2013

You’ve misunderstood how the DataView works. Read https://github.com/mleibman/SlickGrid/wiki/DataView.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - DataView.Sort - more than just asc/desc (need custom sort)
I've got a report being built from a dataset. The dataset uses the Sort property to order the data ...
Read more >
Sort data using a custom list - Microsoft Support
Select the columns to sort. · In the ribbon, click Data > Sort. · In the Sort popup window, in the Sort by...
Read more >
Creating a Custom Sort - YouTube
Sort your data the way you want by creating a custom sort order in a calculated field in Beast Mode. Visit https://www.domo.com/ to...
Read more >
Custom Sorting in Power BI - phData
See the column above named Sort. Bringing in Sort Table to Data Model. Now that we've set up the Sort Table ...
Read more >
Custom sort order for dataview table - Obsidian Forum
Hi, I'm trying to sort a dataview table by a custom order. I have a sequence of statuses for actions (at the moment...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found