简体   繁体   中英

Ag-Grid multi sort columns without key

I have implemented sorting of the the selected items in AG-Grid on a button click other than header click.
Ag grid by default needs a ctrl/shift key to be pressed while selecting multiple columns. I want to override this behavior and use the above button as flag instead of key press.


Is it possible to do this? I do not want Pinned rows.

You can use the ag-grid sorting API. It is documented here . Using this you can update the sort model on button click.

Did some hack and made it work.

 /*onGridReady of ag-grid options*/ onGridReady: () => this.agHeaderClickListener() /** This function adds listener to Ag grid header click event for all columns */ agHeaderClickListener() { console.log( this.elRef.nativeElement.querySelectorAll('.ag-header-cell-label')); let nodeList = this.elRef.nativeElement.querySelectorAll('.ag-header-cell-label'); for (let node of nodeList) { /** IE Fix */ if (node.addEventListener) { node.addEventListener('click', this.selectionChanged.bind(this)); } else { node.attachEvent('onclick', this.selectionChanged.bind(this)); } } } 

use the selectionChanged(event: any) to do the logical changes you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM