@@ -42,11 +42,10 @@ const ColumnHeader = ({
4242 const ref = useRef < HTMLButtonElement > ( undefined ! ) ;
4343 const currentColumn = getCurrentColumn ( ) ;
4444 const currentSortedColumns = api . getColumnState ( ) . filter ( ( c ) => c . sort ) ;
45- const columnNumber = column . sort
46- ? currentSortedColumns . length > 1
47- ? currentSortedColumns . findIndex ( ( c ) => c . colId === column . colId ) + 1
48- : ""
49- : "" ;
45+ const columnNumber =
46+ column . sort && currentSortedColumns . length > 1
47+ ? `${ column . sortIndex + 1 } `
48+ : "" ;
5049
5150 const displayColumnMenu = ( ) => {
5251 if ( currentColumn ) {
@@ -68,6 +67,7 @@ const ColumnHeader = ({
6867 newColumnState . push ( {
6968 colId : column . colId ,
7069 sort : direction ,
70+ sortIndex : newColumnState . length ,
7171 } ) ;
7272 } else {
7373 newColumnState [ colIndex ] . sort = direction ;
@@ -89,7 +89,10 @@ const ColumnHeader = ({
8989 api . applyColumnState ( {
9090 state : api
9191 . getColumnState ( )
92- . filter ( ( c ) => c . sort && c . colId !== column . colId ) ,
92+ . sort ( ( a , b ) => a . sortIndex - b . sortIndex )
93+ . filter ( ( c ) => c . sort && c . colId !== column . colId )
94+ // After we remove the column, lets reindex what's left
95+ . map ( ( c , sortIndex ) => ( { ...c , sortIndex } ) ) ,
9396 defaultState : { sort : null } ,
9497 } ) ,
9598 dismissMenu : ( ) => setColumnMenu ( undefined ) ,
0 commit comments