MCPcopy Index your code
hub / github.com/bvaughn/react-virtualized / sort

Function sort

source/Table/createMultiSort.js:55–102  ·  view source on GitHub ↗
({
    defaultSortDirection,
    event,
    sortBy: dataKey,
  }: SortParams)

Source from the content-addressed store, hash-verified

53 });
54
55 function sort({
56 defaultSortDirection,
57 event,
58 sortBy: dataKey,
59 }: SortParams): void {
60 if (event.shiftKey) {
61 // Shift + click appends a column to existing criteria
62 if (sortDirection[dataKey] !== undefined) {
63 sortDirection[dataKey] =
64 sortDirection[dataKey] === 'ASC' ? 'DESC' : 'ASC';
65 } else {
66 sortDirection[dataKey] = defaultSortDirection;
67 sortBy.push(dataKey);
68 }
69 } else if (event.ctrlKey || event.metaKey) {
70 // Control + click removes column from sort (if pressent)
71 const index = sortBy.indexOf(dataKey);
72 if (index >= 0) {
73 sortBy.splice(index, 1);
74 delete sortDirection[dataKey];
75 }
76 } else {
77 // Clear sortBy array of all non-selected keys
78 sortBy.length = 0;
79 sortBy.push(dataKey);
80
81 // Clear sortDirection object of all non-selected keys
82 const sortDirectionKeys = Object.keys(sortDirection);
83 sortDirectionKeys.forEach(key => {
84 if (key !== dataKey) delete sortDirection[key];
85 });
86
87 // If key is already selected, reverse sort direction.
88 // Else, set sort direction to default direction.
89 if (sortDirection[dataKey] !== undefined) {
90 sortDirection[dataKey] =
91 sortDirection[dataKey] === 'ASC' ? 'DESC' : 'ASC';
92 } else {
93 sortDirection[dataKey] = defaultSortDirection;
94 }
95 }
96
97 // Notify application code
98 sortCallback({
99 sortBy,
100 sortDirection,
101 });
102 }
103
104 return {
105 sort,

Callers 2

simulateFunction · 0.85
_createColumnMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…