Tabulator: Sorting of empty cells and row groups

Created on 16 Oct 2017  路  6Comments  路  Source: olifolkerd/tabulator

I am using a custom sorting function on one of my columns with field name of "los" using data from a different column with field name "elapsed":

 sorter: function(a, b, aRow, bRow, sorterParams) {
          return (aRow.getData().elapsed) - (bRow.getData().elapsed);
        }

I would like to achieve 2 things:

  1. when I sort the "los" column with the custom sorter function, if any of the cells in "elapsed" are empty, I would like the rows containing these empty cells to remain at the bottom, not come to the top when dir="asc"

i.e what I want to achieve is:

image

but the default sorting behaviour of tabulator is resulting in:

image

  1. I have several row groups dictated by another (invisible) column field. When I sort using a custom sorting function I would like the row groups to remain static and the rows within them to be sorted according to the criteria above. Currently tabulator will move the row groups up and down depending on the values of cells in the rows within them. A similar question was raised in issue #483 but the solution given would not work with custom sorter functions as it relies on replacing the sorting function with a headerClick function that has to be the same for all columns?

If these things are not possible, would you consider adding into a future tabulator release ability to 'ignore blanks' on sorting and 'fix row groups' on sorting?

Question - Ask On Stack Overflow

Most helpful comment

@olifolkerd
There is now a tabulator tag on SO.

All 6 comments

Hey @tomheaps,

Sorry for the delay in getting back to you on this one, i have been moving house so not had much free time the last few weeks.

you can certainly do this, in the latest version of Tabulator there are additional arguments passed into the sorter function:

sorter:function(a, b, aRow, bRow, column, dir, sorterParams){

The dir argument lets you know if it is being sorted asc or desc which would let you choose how to sort the empty columns in these situations:

sorter:function(a, b, aRow, bRow, column, dir, sorterParams){
    if(dir == "asc"){
        return (aRow.getData().elapsed || 9999999999) - (bRow.getData().elapsed || 9999999999);
    }else{
        return (aRow.getData().elapsed) - (bRow.getData().elapsed);
    } 
}

The above example is overly simplistic but it should give you an idea of where to go

Let me know if that helps,

Cheers

Oli

No worries. I suspected something was going on in your life because you weren't answering issues in your usual ultra-rapid fashion!! I have been trying to help out and answer some questions whenever I can. I have been noticing that as the popularity of tabulator grows (as it inevitably will given it is such an awesome piece of coding) that more and more people are posting banal questions, making very little effort to read the documentation (which would answer their questions) or expecting you to provide a free coding service.

Have you ever considered creating a tabulator tag on stack overflow, restricting issues on github to genuine bugs/feature requests and directing all other questions for help with coding to stack overflow to minimize your workload??

I had noticed you were answering a load of the questions, thanks for helping out and taking some of the load on yourself, it has been a great help!

And thanks for your kind words about Tabulator :D

Sadly i haven't contributed as much as i would like to stack overflow so don't have enough rep to create a tag yet, but i do like that idea a lot, it would keep the issues list clear for actual bug/feature requests. I have been answering the few questions that have been asked there. i dont suppose you have enough rep to add a tag? if we can get one created i will update the documentation on the website to direct people to ask questions in stack overflow.

Cheers

Oli

Unfortunately, like yourself, I have a poor rep on SO (39 points only) and 1500 are required to create new tags. We could try asking @mikeshow who is the only other person I have seen regularly contributing to the tabulator issues pages?

@olifolkerd
There is now a tabulator tag on SO.

AMAZING!, Thanks @E3V3A

Was this page helpful?
0 / 5 - 0 ratings