MCPcopy Create free account
hub / github.com/AllenFang/react-bootstrap-table / setSortInfo

Method setSortInfo

src/store/TableDataStore.js:69–116  ·  view source on GitHub ↗
(order, sortField)

Source from the content-addressed store, hash-verified

67 }
68
69 setSortInfo(order, sortField) {
70 if (typeof order !== typeof sortField) {
71 throw new Error('The type of sort field and order should be both with String or Array');
72 }
73 if (Array.isArray(order) && Array.isArray(sortField)) {
74 if (order.length !== sortField.length) {
75 throw new Error('The length of sort fields and orders should be equivalent');
76 }
77 order = order.slice().reverse();
78 this.sortList = sortField.slice().reverse().map((field, i) => {
79 return {
80 order: order[i],
81 sortField: field
82 };
83 });
84 this.sortList = this.sortList.slice(0, this.multiColumnSort);
85 } else {
86 const sortObj = {
87 order: order,
88 sortField: sortField
89 };
90
91 if (this.multiColumnSort > 1) {
92 let i = this.sortList.length - 1;
93 let sortFieldInHistory = false;
94
95 for (; i >= 0; i--) {
96 if (this.sortList[i].sortField === sortField) {
97 sortFieldInHistory = true;
98 break;
99 }
100 }
101
102 if (sortFieldInHistory) {
103 if (i > 0) {
104 this.sortList = this.sortList.slice(0, i);
105 } else {
106 this.sortList = this.sortList.slice(1);
107 }
108 }
109
110 this.sortList.unshift(sortObj);
111 this.sortList = this.sortList.slice(0, this.multiColumnSort);
112 } else {
113 this.sortList = [ sortObj ];
114 }
115 }
116 }
117
118 cleanSortInfo() {
119 this.sortList = [];

Callers 3

getTableDataFunction · 0.80
BootstrapTable.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected