Custom sorting in Data View
See original GitHub issueI 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:
- Created 10 years ago
- Comments:9 (5 by maintainers)
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?
You’ve misunderstood how the DataView works. Read https://github.com/mleibman/SlickGrid/wiki/DataView.