I want the default sort order in descending order when I click a column in Handsontable.

Asked 2 years ago, Updated 2 years ago, 38 views

Handsontable sets columnSorting:true to sort in ascending order when you click on a column header, and then click again to sort in descending order. Can I change this to descending order by clicking the first click?

*Additional information

I understand that the sort order in the initial display state can be specified as follows, but

var hot=new Handsontable( document.getElementById('grid'), {
  columnSorting: {
    column —3,
    sortOrder: false // descending order
  }
});

If you click on a column header even with this specification, it will be in ascending → descending order.

Do I have no choice but to customize the source…

source.

javascript

2022-09-30 20:30

1 Answers

Self-resolved.

When I followed the source, it didn't seem like an API setting, so I responded by customizing the source.

this.setSortingColumn=function(col,order){
  var instance = this;

  if(typeofcol=='undefined'){
    delete instance.sortColumn;
    delete instance.sortOrder;

    return;
  } else if(instance.sortColumn===col&&typeoforder=='undefined'){
    instance.sortOrder=!instance.sortOrder;
  } else{
    // instance.sortOrder=typeoforder!='undefined'?order:true;// Here
    instance.sortOrder=typeoforder!='undefined'?order:false;//false
  }

  instance.sortColumn=col;
};

This is the definition of the setSortingColumn in line 0.12.28857.


2022-09-30 20:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.