Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _columnClick = (ev: React.MouseEvent, column: IColumn): void => {
// Find the field in the viewFields list
const columnIdx = findIndex(this.props.viewFields, field => field.name === column.key);
// Check if the field has been found
if (columnIdx !== -1) {
const field = this.props.viewFields[columnIdx];
// Check if the field needs to be sorted
if (has(field, 'sorting')) {
// Check if the sorting option is true
if (field.sorting) {
const sortDescending = typeof column.isSortedDescending === 'undefined' ? false : !column.isSortedDescending;
const sortedItems = this._sortItems(this.state.items, column.key, sortDescending);
// Update the columns
const sortedColumns = this.state.columns.map(c => {
if (c.key === column.key) {
c.isSortedDescending = sortDescending;
c.isSorted = true;
} else {
c.isSorted = false;
c.isSortedDescending = false;
}
return c;
});
// Update the grouping