table icon indicating copy to clipboard operation
table copied to clipboard

How to customize sort icon in header cell?

Open rockdigit opened this issue 9 years ago • 12 comments

I am wondering if it is possible to custom sort icon

Currently sort icon is defined as below .ReactTable .rt-thead .rt-th.-sort-asc, .ReactTable .rt-thead .rt-td.-sort-asc { -webkit-box-shadow: inset 0 3px 0 0 rgba(0,0,0,0.6); box-shadow: inset 0 3px 0 0 rgba(0,0,0,0.6); }

I want to change it into arrow up/down icon corresponding to the sort order

rockdigit avatar Aug 19 '17 13:08 rockdigit

Since this is more of an implementation question and not an issue or bug, we suggest you use our slack channel to ask for more assistance. Thanks!

tannerlinsley avatar Sep 01 '17 04:09 tannerlinsley

was there a solution for this? I am looking for one to build.. Please let me know if you have accomplished changing sort icons to arrows. thanks

kasarlavinaysrivastav avatar Jul 30 '18 15:07 kasarlavinaysrivastav

A CSS Solution if you want to use a sorting up/down icon. This solution is for resizable columns enabled.

.ReactTable .rt-resizable-header {
    padding: 6px 24px !important;
    -webkit-box-shadow: none !important;
    box-shadow: none !important;
}
 
.ReactTable .rt-resizer:before {
    display: inline-block;
    position: absolute;
    right: 25px;
    top: 3px;
    height: 18px;
    width: 18px;
    color: transparent;
    content: '.';
    background-size: 18px 18px;
    background-repeat: no-repeat; 
    opacity: 0.87;
}

.ReactTable  .rt-resizable-header-content:after {
    position: absolute;
    right: 8px;
    top: 3px;
    height: 18px;
    width: 18px;
    z-index: 120;
    color: transparent;
    content: '.';
}

.ReactTable .rt-th.-sort-asc .rt-resizer:before {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTAgMTVWNmw0IDQgMS0xLTYtNi02IDYgMSAxIDQtNHY5eiIgZmlsbD0iIzMzMyIvPjwvc3ZnPg==);
}

.ReactTable .rt-th.-sort-desc .rt-resizer:before {
    background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTgiIGhlaWdodD0iMTgiIHZpZXdCb3g9IjAgMCAxOCAxOCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNOCAzdjkuMTNMNCA4IDMgOWw2IDYgNi02LTEtMS00IDQuMTNWM3oiIGZpbGw9IiMzMzMiLz48L3N2Zz4=);
}

andrewaxelrod avatar Aug 27 '18 21:08 andrewaxelrod

@andrewaxelrod please tell me the steps on how to override the default react-table sorting css with the CSS solution you provided? Thanks

Aaron-Lei avatar Oct 29 '18 08:10 Aaron-Lei

@Aaron-Lei You should be able to place it anywhere. It all depends on what you are using for the build process. For example, if you are using create react app, then you can drop this css into the App.css within the root directory.

andrewaxelrod-ist avatar Nov 01 '18 16:11 andrewaxelrod-ist

.MyReactTableClass {
  .-sort-desc {
    box-shadow: none !important;
    &:before {
      content: "â–¼";
      float: right;
    }
  }

  .-sort-asc {
    box-shadow: none !important;
    &:before {
      content: "â–²";
      float: right;
    }
  }
}

nmaties avatar Jan 22 '19 17:01 nmaties

for a pure js way, you can do

import find from 'lodash/find';

const getTheadThProps = (table, row, col) => {
  const sortedCol = find(table.sorted, { id: col.id });
  const boxShadow =
    sortedCol ? `inset 0px ${sortedCol.desc ? -3 : 3}px 0px 0px ${colors.lightBlue}` : '';
  return {
    style: {
      ..._styles.thead,
      boxShadow,
    },
  };
};

<ReactTable
  data={data}
  columns={columns}
  getTheadThProps={getTheadThProps}
/>

SimonVuong avatar Feb 04 '19 17:02 SimonVuong

@SimonVuong got _styles and colors not found, what's these two variables?

binglinglanyun avatar Jul 26 '19 14:07 binglinglanyun

you can give it like

<BaseTable
    components={components}
    fixed
/>

and

const components = {
      SortIndicator:  customSortComponent,
   // ...other components
    };

after that you can define your custom sort icon

CustomSort = (props) => {
    return (
      <div>
     {
     props.sortOrder === 'desc' ? ':)' : ':('
     }
      </div>
    );
  }

fekajin avatar Nov 16 '20 14:11 fekajin

How to show both up, down arrow for only sortable enabled columns? so user can know those are sortable column. For columns sortable=false should has no icon, only sortable columns will show default sort icon.

whitesnow9291 avatar Mar 04 '21 10:03 whitesnow9291

@whitesnow9291 Did you find any solution?

manisha-planetrics avatar Mar 26 '23 15:03 manisha-planetrics

@manisha-planetrics, @whitesnow9291 you can use default option for column disableSortBy

Lullabyq avatar Oct 18 '23 14:10 Lullabyq