-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from bartoval/hide_columns_programmatically
refactor(General): ♻️ Hide table columns programmatically
- Loading branch information
Showing
14 changed files
with
86 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getValueFromNestedProperty } from '@core/utils/getValueFromNestedProperty'; | ||
import { NonNullableValue, SKTableColumn } from '@sk-types/SkTable.interfaces'; | ||
|
||
type ColumnVisibilityConfig<T> = { | ||
[key in keyof T]?: boolean; | ||
}; | ||
|
||
/** | ||
* Sets the visibility of table columns based on the provided visibility configuration. | ||
*/ | ||
export function setColumnVisibility<T>( | ||
tableColumns: SKTableColumn<T>[], | ||
visibilityConfig: Partial<ColumnVisibilityConfig<T>> = {} | ||
): SKTableColumn<T>[] { | ||
return tableColumns.map((column) => { | ||
if (column.prop && column.prop in visibilityConfig) { | ||
return { | ||
...column, | ||
show: visibilityConfig[column.prop] | ||
}; | ||
} | ||
|
||
return { | ||
...column, | ||
show: column.show ?? true | ||
}; | ||
}); | ||
} | ||
|
||
export function sortRowsByColumnName<T>(rows: NonNullableValue<T>[], columnName: string, direction: number) { | ||
return rows.sort((a, b) => { | ||
// Get the values of the sort column for the two rows being compared, and handle null values. | ||
const paramA = getValueFromNestedProperty(a, columnName.split('.') as (keyof T)[]); | ||
const paramB = getValueFromNestedProperty(b, columnName.split('.') as (keyof T)[]); | ||
|
||
if (paramA == null || paramB == null || paramA === paramB) { | ||
return 0; | ||
} | ||
|
||
return paramA > paramB ? direction : -direction; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.